	********************************************************************************************************************************************
	*
	*	 OVERVIEW
	*		This code runs the analysis and replicates all the figures and tables for the paper: 
	*		"A Mother's Voice: Impacts of Spousal Communication Training on Child Health Investments"
	*
	********************************************************************************************************************************************

	* Housekeeping
	
	version 17
	cap log close		
	set more off
	clear all

	* Set directory to replication folder
 
	global maindir "C:\Users\celin\Dropbox\USAID Uganda Analysis\Replication\Replication package\mothersvoice_replication"
	cd "${maindir}"

	* Set globals for output

	global dofiles "${maindir}/Dofiles"
	global figures "${maindir}/Output/Figures"
	global tables "${maindir}/Output/Tables"
	adopath ++ "${maindir}/Ado"

	global data "${maindir}/Data"
	global intermediate "${data}/Intermediate data"
	global analysis "${data}/Analysis"

	* Select which tables to produce by setting each to 0 or 1 below: 
	*		NOTE: when running this for the first time, make sure to select local=1 for all tables 1-5 
	* 		this ensures that baseline values of indices are saved in the relevant "intermediate data" folder
	* 		we use these for Baseline Checks (Appendix Table A1) + Heterogeneity in Attrition by Baseline Characteristics (Appendix Table A2b)
	
	local table_1 = 1
	local table_2 = 1	
	local table_3 = 1	
	local table_4 = 1	
	local table_5 = 1	
	local table_a1 = 1	
	local table_a2a = 1	
	local table_a2b = 1	
	local table_a3a = 1	
	local table_a3b = 1	
	local table_a3c = 1	
	local table_a3d = 1	
	local table_a3e = 1	
	local table_a4a = 1	
	local table_a4b = 1	
	local table_a5a = 1
	local table_a5b = 1			
	local table_a5c = 1			
	local table_a5d = 1			
	local table_a6a = 1			
	local table_a6b = 1	
	local table_a7 = 1
	local table_a8 = 1
	local figure_a1 = 1
	
*===============================================================================*
* Table 1: Program impacts on effective communication between spouses.
*===============================================================================*
	
	if `table_1' == 1 {
	
	use "$analysis/womens_mens_mcm.dta", clear
	
	tab districtid, gen(district)
	drop district4 
	
	estimates clear
	
	lab var wemp "WCommHN"
	
	*** (1) RELATIONSHIP IMPROVEMENTS
	
	forval i = 1/6 {
		replace Ew_rel_improve`i'=0 if Ew_rel_year_imp==0
		replace Em_rel_improve`i'=0 if Em_rel_year_imp==0
	}
	
	* Generate standardized variables
	foreach var of varlist Ew_rel_improve1-Ew_rel_improve6 Em_rel_improve1-Em_rel_improve6 {
		cap drop A`var'
		sum `var' if control==1
		gen A`var'=(`var'-`r(mean)')/`r(sd)'
	}
	
	* ASTE
	cap drop Ew_rel_improve_aste Em_rel_improve_aste
	egen Ew_rel_improve_aste = rowmean(AEw_rel_improve*)
	egen Em_rel_improve_aste = rowmean(AEm_rel_improve*)
	
	*** (2) WOMAN PART OF DECISION-MAKING

	*** Recoding Household Variables
	** Household Decisions
	* women's reports:
	local HD  w_wmoney w_purch w_savespend w_wcloth w_ccloth w_daily w_chealth w_cfeed w_cschool 
	local EHD Ew_wmoney Ew_purch Ew_savespend Ew_wcloth Ew_ccloth Ew_daily Ew_chealth Ew_cfeed Ew_cschool 
	local HDW w_wmoney w_daily w_chealth w_cfeed   
	local EHDW Ew_wmoney Ew_daily Ew_chealth Ew_cfeed   
	* men's reports:
	local HDM m_wmoney m_daily m_chealth m_cfeed 
	local EHDM Em_wmoney Em_daily Em_chealth Em_cfeed
	
	* define "woman has say" variable as equal to 1 if the woman reports making the decision alone OR jointly with her husband, and 0 otherwise	
	* define "joint decision" variable as equal to 1 if the woman reports making the decision jointly with her husband, and 0 otherwise	
	
	foreach var in `HD' `EHD' `EHDM' {
		replace `var'_bi = `var'_who
		recode `var'_bi (3 = 1) (2 4 5 = 0) (6 99=.)
		gen `var'_joint=`var'_who==3
		replace `var'_joint=. if inlist(`var'_who,6,99)
		replace `var'_joint=. if `var'_bi==.
	}	
	
	foreach var in `HDM' {
		replace `var'_bi = `var'_who
		recode `var'_bi (2 3 = 1) (1 4 5 = 0) (6 99=.)
		gen `var'_joint=`var'_who==3
		replace `var'_joint=. if inlist(`var'_who,6,99)
		replace `var'_joint=. if `var'_bi==.
	}		
	
	*** Women
	** Household Decisions
	local astevarw2 w_wmoney_bi w_daily_bi w_chealth_bi w_cfeed_bi w_savespend_bi w_wcloth_bi w_purch_bi w_cschool_bi w_ccloth_bi 
	local Eastevarw2 Ew_wmoney_bi Ew_daily_bi Ew_chealth_bi Ew_cfeed_bi Ew_savespend_bi Ew_wcloth_bi Ew_purch_bi Ew_cschool_bi Ew_ccloth_bi 
	local astevarw_joint w_wmoney_joint w_daily_joint w_chealth_joint  w_cfeed_joint w_savespend_joint w_wcloth_joint w_purch_joint w_cschool_joint w_ccloth_joint 
	local Eastevarw_joint Ew_wmoney_joint Ew_daily_joint Ew_chealth_joint Ew_cfeed_joint Ew_savespend_joint Ew_wcloth_joint Ew_purch_joint Ew_cschool_joint Ew_ccloth_joint 
	
	*** Men 
	** Household Decisions 
	local astevarm2  m_wmoney_bi  m_daily_bi m_chealth_bi m_cfeed_bi 
	local Eastevarm2 Em_wmoney_bi Em_daily_bi Em_chealth_bi Em_cfeed_bi
	local astevarm_joint m_wmoney_joint m_daily_joint m_chealth_joint m_cfeed_joint 
	local Eastevarm_joint Em_wmoney_joint Em_daily_joint Em_chealth_joint Em_cfeed_joint 
	
	*** ASTE, men's and women's reports
	
	cap drop a_w_*_bi a_Ew_*_bi
	cap drop a_m_*_bi a_Em_*_bi
	
	* Generate standardized variables
	foreach var in `astevarw2' `astevarm2' `astevarw_joint' `astevarm_joint' {
		cap drop a_`var'
		qui sum `var' if control == 1
		gen a_`var'=(`var'-`r(mean)')/`r(sd)'
		cap drop a_E`var'
		qui sum E`var' if control == 1
		gen a_E`var'=(E`var'-`r(mean)')/`r(sd)'
	}
	
	foreach y in w m {
		foreach x in bi joint {
			cap drop aste_`y'_`x' Easte_`y'_`x'
			egen aste_`y'_`x' = rowmean(a_`y'_*_`x')
			egen Easte_`y'_`x' = rowmean(a_E`y'_*_`x')
		}
	}
	
	*** (3) HUSBAND LESS VIOLENT 

	foreach var in w_humil w_threat w_insult w_beat w_push w_slap w_violent {
		cap drop `var'_no 
		gen `var'_no=1 if `var'freq==3 // no such violence from husband in past year or month
		replace `var'_no=1 if `var'==0 // never been violent in that way
		replace `var'_no=0 if inlist(`var'freq,1,2) // often or sometimes in past year or month
		
		cap drop E`var'_no 
		gen E`var'_no=1 if E`var'freq==3 // no such violence from husband in past year or month
		replace E`var'_no=1 if E`var'==0 // never been violent in that way
		replace E`var'_no=0 if inlist(E`var'freq,1,2) // often or sometimes in past year or month
	}
	
	* Generate standardized variables	
	foreach var in w_humil_no w_threat_no w_insult_no w_beat_no w_push_no w_slap_no w_violent_no {
		sum E`var' if control==1
		replace E`var'=(E`var'-`r(mean)')/`r(sd)'
	}
	
	foreach var in w_humil_no w_threat_no w_insult_no w_beat_no w_push_no w_slap_no w_violent_no {
		sum `var' if control==1
		replace `var'=(`var'-`r(mean)')/`r(sd)'
	}
	
	local Evarlist Ew_humil_no Ew_threat_no Ew_insult_no Ew_beat_no Ew_push_no Ew_slap_no Ew_violent_no 
	local varlist w_humil_no w_threat_no w_insult_no w_beat_no w_push_no w_slap_no w_violent_no 
	
	* Generate averaged outcome
	cap drop aste_vbeh_w Easte_vbeh_w
	egen Easte_vbeh_w=rowmean(`Evarlist')
	egen aste_vbeh_w=rowmean(`varlist')
	
	* Normalize all ASTEs so that SD=1
	local astelist w_rel_improve_aste m_rel_improve_aste aste_m_bi aste_m_joint aste_w_bi aste_w_joint aste_vbeh_w
	foreach var in `astelist' {
		cap confirm variable `var'
		if !_rc {
			sum `var' if control==1
			replace `var'=(`var'-`r(mean)')/`r(sd)'		
		}
		sum E`var' if control==1
		replace E`var'=(E`var'-`r(mean)')/`r(sd)'		
	}	
	
	******** REGRESSIONS
	
	local covars wemp whn mhn
	local controls district? 
	 			
	** Women
	foreach y in w_rel_improve_aste aste_w_bi aste_w_joint aste_vbeh_w {
		cap confirm variable `y'
		if !_rc {
			eststo est`y': reghdfe E`y' `y' wemp whn mhn `controls', a(stratum) cluster(villageid)
		}
		else eststo est`y': reghdfe E`y' wemp whn mhn `controls', a(stratum) cluster(villageid) 
		sum E`y' if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`y'
		test whn=wemp
			estadd scalar pval1 = r(p): est`y'
		test wemp=mhn
			estadd scalar pval2 = r(p): est`y'
		test whn=mhn
			estadd scalar pval3 = r(p): est`y'
	}	
	
	#delimit ;
	esttab using "$tables/table_1.tex", 
	b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs style(tex) 
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none)
		order(wemp whn mhn) prehead("{ \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
		\begin{tabular}{l*{4}{c}} \toprule \toprule
		&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}\\ 
		\midrule
		&\multicolumn{1}{c}{Relationship} &\multicolumn{1}{c}{Wife part of} &\multicolumn{1}{c}{Couple makes} &\multicolumn{1}{c}{Husband} \\
		&\multicolumn{1}{c}{improved} &\multicolumn{1}{c}{household} &\multicolumn{1}{c}{decisions} &\multicolumn{1}{c}{is less} \\
		&\multicolumn{1}{c}{ASTE} &\multicolumn{1}{c}{decisions} &\multicolumn{1}{c}{together} &\multicolumn{1}{c}{violent} \\
		&\multicolumn{1}{c}{} &\multicolumn{1}{c}{ASTE} &\multicolumn{1}{c}{ASTE} &\multicolumn{1}{c}{ASTE} \\
		\midrule") 
		postfoot("\bottomrule \bottomrule \end{tabular} }") posthead(" ")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean of outcome" " " "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f  %20s %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr	

	** SAVE BASELINE INDICES HERE FOR BASELINE CHECKS TABLE BELOW
	
	keep id aste_w_bi aste_w_joint aste_vbeh_w 
	save "$intermediate\baseline_aste_relationship_tab1", replace
}
	
*=====================================================================================*
* Table 2: Program impacts on frequency of spousal discussion about targeted health 
*          topics and women's and men's health knowledge.
*=====================================================================================*

	if `table_2' == 1 {	

	eststo clear	
	estimates clear
	
	use "$analysis/womens_mens_mcm.dta", clear
	
	tab districtid, gen(district)
	drop district4	
	
	recode m_fp_talk (98=.)
	
	foreach y in w_fp_talk m_fp_talk Ew_fp_talk Em_fp_talk {
		gen `y'_yno = 0 if `y' == 1
		replace `y'_yno = 1 if inlist(`y',2,3)
	}
	
	lab var wemp "WCommHN"
	local covars wemp whn mhn
	local controls district? 
	
	eststo estimationFP: areg Ew_fp_talk_yno w_fp_talk_yno wemp whn mhn `controls', absorb(stratum) cluster(villageid)
		sum Ew_fp_talk_yno if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimationFP
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimationFP
		test whn=wemp
			estadd scalar pval1 = r(p): estimationFP
		test wemp=mhn
			estadd scalar pval2 = r(p): estimationFP
		test whn=mhn
			estadd scalar pval3 = r(p): estimationFP
			
	** (2) Discuss HIV
	
	gen Ew_talk_hiv = (Ew_talked_hiv == 1) if !mi(Ew_talked_hiv)
	
	eststo estimationHIV: areg Ew_talk_hiv wemp whn mhn `controls', absorb(stratum) cluster(villageid)
		sum Ew_talk_hiv if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimationHIV
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimationHIV
		test whn=wemp
			estadd scalar pval1 = r(p): estimationHIV
		test wemp=mhn
			estadd scalar pval2 = r(p): estimationHIV
		test whn=mhn
			estadd scalar pval3 = r(p): estimationHIV
	
	** (3) Discuss Health & Nutrition

	local varlist w_husb_sugg_food_vo w_discuss_spouse_vo w_husb_sugg_hc_vo
	
	foreach var in `varlist' {
		sum E`var' if control == 1
		gen EE`var'=(E`var'-`r(mean)')/`r(sd)'
	}
	
	* ASTE, normalized so that SD=1
	
	cap drop EWhusb_HnN_index
	egen EWhusb_HnN_index=rowmean(EEw_husb_sugg_food_vo EEw_discuss_spouse_vo EEw_husb_sugg_hc_vo)	
	sum EWhusb_HnN_index if control==1
	replace EWhusb_HnN_index=(EWhusb_HnN_index-`r(mean)')/`r(sd)'		
		
	eststo estimationHnN: areg EWhusb_HnN_index wemp whn mhn `controls', a(stratum) cluster(villageid)
		sum EWhusb_HnN_index if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimationHnN
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimationHnN
		test whn=wemp
			estadd scalar pval1 = r(p): estimationHnN
		test wemp=mhn
			estadd scalar pval2 = r(p): estimationHnN
		test whn=mhn
			estadd scalar pval3 = r(p): estimationHnN
	
	** (4) Discuss household spending	
	
	eststo estimationS: areg Ew_plan_hhexpend12 w_plan_hhexpend6 wemp whn mhn `controls', a(stratum) cluster(villageid)
		sum Ew_plan_hhexpend12 if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimationS
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimationS
		test whn=wemp
			estadd scalar pval1 = r(p): estimationS
		test wemp=mhn
			estadd scalar pval2 = r(p): estimationS
		test whn=mhn
			estadd scalar pval3 = r(p): estimationS
			
	** (5) Overall ASTE (Woman)
	
	gen Ew_plan_hhexpend6 = Ew_plan_hhexpend12
		
	local varlist w_fp_talk_yno w_talk_hiv w_plan_hhexpend6
	
	foreach var in `varlist' {
	cap confirm variable `var'
		if !_rc {
			sum `var' if control == 1
			gen B`var'=(`var'-`r(mean)')/`r(sd)'
		}
		sum E`var' if control == 1
		gen EE`var'=(E`var'-`r(mean)')/`r(sd)'
	}
	
	egen Ew_marcomm_aste = rowmean(EEw_fp_talk_yno EEw_talk_hiv EEw_husb_sugg_food_vo EEw_discuss_spouse_vo EEw_husb_sugg_hc_vo EEw_plan_hhexpend6)
	egen w_marcomm_aste = rowmean(Bw_fp_talk_yno Bw_plan_hhexpend6)
	
	foreach var in w_marcomm_aste Ew_marcomm_aste {
		sum `var' if control==1
		replace `var'=(`var'-`r(mean)')/`r(sd)'				
	}
	
	eststo estimationC: areg Ew_marcomm_aste w_marcomm_aste wemp whn mhn `controls', a(stratum) cluster(villageid)
		sum Ew_marcomm_aste if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimationC
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimationC
		test whn=wemp
			estadd scalar pval1 = r(p): estimationC
		test wemp=mhn
			estadd scalar pval2 = r(p): estimationC
		test whn=mhn
			estadd scalar pval3 = r(p): estimationC				
			
	** (6) Health Knowledge: change Knowledge ASTE to capture knowledge with respect to entire sample, not men and women separately 
	
	expand=2
	bys id: gen n=_n
	lab define GENDER 1 "Woman" 2 "Man", modify
	lab values n GENDER
	
	#delimit ;
	local health_knowledge_vars
		cstrum_impt_why_bi
		ageliquid_6
		agefood_6
		grow_lackdiet_vm
		bfeed24
		timedeworm_5
		child_worms_bi
		child_vomit_bi
		boys_eatmore_bi
		safe_primhc_bi
		menprot_bi
		anem_foods_bi 
		boil_1min_bi
		condom_times_bi
		hygint_bi
		food_plate_bi ;
	#delimit cr
	
	foreach var in `health_knowledge_vars' {
		cap confirm variable m_`var'     // if the variable exists for men, it also exists for women 
		if !_rc {   
			gen B`var'=w_`var' if n==1
			replace B`var'=m_`var' if n==2
		}	
		cap confirm variable Em_`var'   // if the variable exists for men, it also exists for women 
		if !_rc {            
			gen E`var'=Ew_`var' if n==1
			replace E`var'=Em_`var' if n==2
		}	
		* standardize with respect to control group
		cap confirm variable B`var'
		if !_rc {
			sum B`var' if control == 1 // stats for entire sample = men + women 
			gen BL_`var'=(B`var'-`r(mean)')/`r(sd)' // baseline health knowledge
		}
		cap confirm variable E`var'
		if !_rc {
			sum E`var' if control == 1 // stats for entire sample = men + women 
			gen EL_`var'=(E`var'-`r(mean)')/`r(sd)' // endline health knowledge
		}
	}
	
	//// Endline index

	cap drop *Hknowl_index 
		
  	#delimit ;
	egen EL_Hknowl_index = rowmean(	
		EL_cstrum_impt_why_bi
		EL_ageliquid_6
		EL_agefood_6
		EL_grow_lackdiet_vm
		EL_bfeed24
		EL_timedeworm_5
		EL_child_worms_bi
		EL_child_vomit_bi
		EL_boys_eatmore_bi
		EL_safe_primhc_bi
		EL_menprot_bi
		EL_anem_foods_bi 
		EL_boil_1min_bi
		EL_condom_times_bi
		EL_hygint_bi
		EL_food_plate_bi) 	
	;
	#delimit cr
			
	//// Baseline index
	
	#delimit ;
	egen BL_Hknowl_index = rowmean(
		BL_ageliquid_6
		BL_agefood_6
		BL_grow_lackdiet_vm
		BL_bfeed24
		BL_timedeworm_5
		BL_menprot_bi 
		BL_boil_1min_bi
		BL_hygint_bi)
		;
	#delimit cr
	
	sum BL_Hknowl_index if n==1 // women's baseline health knowledge
	sum BL_Hknowl_index if n==2 // men's baseline health knowledge

	* Normalize ASTEs so that SD=1	
	
	foreach var in BL_Hknowl_index EL_Hknowl_index {
		sum `var' if control==1
		replace `var'=(`var'-`r(mean)')/`r(sd)'				
		sum `var' if control==1	// SD=1
	}
	
	sum BL_Hknowl_index if n==1 // women's baseline health knowledge
	sum BL_Hknowl_index if n==2 // men's baseline health knowledge
	
	** Women's regression: 
	
	eststo est1: areg EL_Hknowl_index wemp whn mhn BL_Hknowl_index `controls' if n==1, a(stratum) cluster(villageid)
		sum EL_Hknowl_index if e(sample)==1 & control==1 & n==1 // women, control group, endline
			local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est1
			local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est1
			test whn=wemp
				estadd scalar pval1=r(p): est1
			test wemp=mhn
				estadd scalar pval2=r(p): est1
			test whn=mhn
				estadd scalar pval3=r(p): est1

	** Men's regression:  
	
	eststo est2: areg EL_Hknowl_index wemp whn mhn BL_Hknowl_index `controls' if n==2, a(stratum) cluster(villageid)
		sum EL_Hknowl_index if e(sample)==1 & control==1 & n==2 // men, control group, endline
			local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est2
			local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est2
			test whn=wemp
				estadd scalar pval1=r(p): est2
			test wemp=mhn
				estadd scalar pval2=r(p): est2
			test whn=mhn
				estadd scalar pval3=r(p): est2
							
					
	***** REGRESSIONS: Table 2: 7 columns ***** 

	#delimit ;
	esttab using "$tables/table_2.tex", 
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs style(tex) 
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none)
		order(wemp whn mhn)
		prehead("{ \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
		\begin{tabular}{l*{7}{c}} \toprule  \toprule 
		&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)} &\multicolumn{1}{c}{(7)}   \\ 
		\midrule
		&\multicolumn{1}{c}{Discusses}&\multicolumn{1}{c}{Discusses}&\multicolumn{1}{c}{Health and}&\multicolumn{1}{c}{Discusses}&\multicolumn{1}{c}{Overall}&\multicolumn{1}{c}{Health}&\multicolumn{1}{c}{Health}\\ 
		&\multicolumn{1}{c}{family}&\multicolumn{1}{c}{HIV with}&\multicolumn{1}{c}{nutrition}&\multicolumn{1}{c}{HH finance}&\multicolumn{1}{c}{discussion}&\multicolumn{1}{c}{knowledge}&\multicolumn{1}{c}{knowledge}\\ 
		&\multicolumn{1}{c}{planning}&\multicolumn{1}{c}{spouse}&\multicolumn{1}{c}{discussion}&\multicolumn{1}{c}{with spouse}&\multicolumn{1}{c}{ASTE}&\multicolumn{1}{c}{ASTE}&\multicolumn{1}{c}{ASTE}\\ 
		&\multicolumn{1}{c}{with spouse}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{ASTE}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}&\multicolumn{1}{c}{(Woman)}&\multicolumn{1}{c}{(Man)}\\ 
		")
		postfoot("\bottomrule \bottomrule \end{tabular} }")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean of outcome" " " "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f  %20s %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr		
	eststo clear
	
	** SAVE BASELINE INDICES HERE FOR BASELINE CHECKS TABLE BELOW
	
	preserve
		keep if n==1
		keep id BL_Hknowl_index
		ren BL_Hknowl_index w_Hknowl_index
		tempfile women 
		sa `women', replace
	restore
	
	keep if n==2
	ren BL_Hknowl_index m_Hknowl_index
	keep id	w_marcomm_aste m_Hknowl_index
	
	merge 1:1 id using `women', nogen
	save "$intermediate\baseline_aste_discussion_knowledge_tab2", replace
	
	}
	

*===============================================================================*
* Table 3: Program impacts on household health behaviors.
*===============================================================================*	
	
	if `table_3' == 1 {	
	
	use "$analysis/womens_mens_mcm.dta", clear
	
	tab districtid, gen(district)
	drop district4		
	
	** 1) Newborn health variables				
					
	** Use this set of outcomes for Newborn Health ASTE: 
	
	local beh2 w_first_check_weeks_bi w_breastfeed w_breastfed_weeks_bi w_bfeed_atemore w_colostrum w_othliq_1week w_othliq_3mo w_food_3mo total_vacc vita_6wk vita_6mo
	local Ebeh2 Ew_first_check_weeks_bi Ew_breastfeed Ew_breastfed_weeks_bi Ew_bfeed_atemore Ew_colostrum Ew_othliq_1week Ew_othliq_3mo Ew_food_3mo Etotal_vacc Evita_6wk Evita_6mo 	
	
	** 2) Maternal health variables (only for mothers who are currently pregnant or have been pregnant in the past 2 years before endline)	
		// 3,860 endline pregnancies in past 2 years, including 780 current pregnancies
	
	* antenatal care
	
	cap drop Ew_latestpreg_ac2 w_latestpreg_ac2
	
	gen Ew_latestpreg_ac2 = Ew_lastpreg_ac if Ew_pregpast2 == 1 
		replace Ew_latestpreg_ac2 = Ew_preg_ac if Ew_pregnow == 1 & Ew_preg_ac!=. 
		
	gen w_latestpreg_ac2 = w_preg_ac2 if w_pregpast2 == 1
		replace w_latestpreg_ac2 = w_preg_ac if w_pregnow == 1 & w_preg_ac!=. 
	
	mdesc Ew_latestpreg_ac2 // 3641 non-missing values at endline
	cou if Ew_latestpreg_ac2!=. & w_latestpreg_ac2!=. // 3446 women have non-missing values for last pregnancy at endline *and* baseline values for same outcome
	
	* did woman eat more of certain foods during last pregnancy
	
	cap drop Ew_latestpreg_foods2 w_latestpreg_foods2	

	gen Ew_latestpreg_foods2 = Ew_lastpreg_foods if Ew_pregpast2 == 1 
		replace Ew_latestpreg_foods2 = Ew_preg_foods if Ew_pregnow == 1 & Ew_preg_foods!=. 
	
	gen w_latestpreg_foods2 = w_lastpreg_foods if w_pregpast2==1
		replace w_latestpreg_foods2 = w_preg_foods if w_pregnow==1 & w_preg_foods!=. 
		
	mdesc Ew_latestpreg_foods2 // 3638 non-missing values at endline
	cou if Ew_latestpreg_foods2!=. & w_latestpreg_foods2!=. // 3443 women have non-missing values for last pregnancy at endline *and* baseline values for same outcome
	
	* received iron during last pregnancy or in 2 months after // should be defined only for completed pregnancies in past 2 years 
			
	** Use this set of outcomes for Maternal Health ASTE: 
	
	local beh3 w_latestpreg_ac2 w_latestpreg_foods2 iron
	local Ebeh3 Ew_latestpreg_ac2 Ew_latestpreg_foods2 Eiron	
	
	** 3) Household sanitary practices variables
		
	** Use this set of outcomes for the Sanitary Practices ASTE: 
	
	local Ebeh1 Em_soap_toilet_bi Em_soap_meal_bi Ew_soap_toilet_bi Ew_soap_meal_bi Ew_treat_water Ew_toilet_sweep_bi Ew_toilet_improv
	local beh1 m_soap_toilet_bi m_soap_meal_bi w_soap_toilet_bi w_soap_meal_bi w_treat_water w_toilet_sweep_bi
	
	// ASTE 		
	forval i = 1/3 {		
		foreach var in `beh`i'' {
		cap confirm variable a_`var', exact
				if !_rc {
					drop a_`var'
				}			
		
		sum `var' if control == 1
			gen a_`var'=(`var'-`r(mean)')/`r(sd)'
		}
		foreach var in `Ebeh`i''  {
		cap confirm variable a_`var', exact
				if !_rc {
					drop a_`var'
				}				
			sum `var' if control == 1
			gen a_`var'=(`var'-`r(mean)')/`r(sd)'
		}
	}	
		
	** Column 1: Newborn Health ASTE
	
	cap drop aste_beh2 Easte_beh2

	local a_beh2 a_w_first_check_weeks_bi a_w_breastfeed a_w_breastfed_weeks_bi a_w_colostrum a_w_othliq_1week a_w_othliq_3mo a_w_food_3mo a_total_vacc a_vita_6wk a_vita_6mo a_w_bfeed_atemore
	local a_Ebeh2 a_Ew_first_check_weeks_bi a_Ew_breastfeed a_Ew_breastfed_weeks_bi a_Ew_colostrum a_Ew_othliq_1week a_Ew_othliq_3mo a_Ew_food_3mo a_Etotal_vacc a_Evita_6wk a_Evita_6mo a_Ew_bfeed_atemore
	
	mdesc `a_beh2' `a_Ebeh2'
	egen aste_beh2 = rowmean(`a_beh2')  
	egen Easte_beh2 = rowmean(`a_Ebeh2')  
	cou if Easte_beh2!=. & aste_beh2!=. // 3,034 non-missing obs
	
	** Column 2: Maternal Health ASTE
	
	cap drop aste_beh3 Easte_beh3 
	cap drop aste_beh0 Easte_beh0
	
	local a_beh3 a_w_latestpreg_ac2 a_w_latestpreg_foods2 a_iron
	local a_Ebeh3 a_Ew_latestpreg_ac2 a_Ew_latestpreg_foods2 a_Eiron
			
	mdesc `a_beh3' `a_Ebeh3'	
	egen aste_beh3 = rowmean(`a_beh3')  
	egen Easte_beh3 = rowmean(`a_Ebeh3')  
	
	** Column 3: Household Sanitary Practices ASTE
	
	cap drop aste_beh1 Easte_beh1
	
	local a_beh1 a_m_soap_toilet_bi a_m_soap_meal_bi a_w_soap_toilet_bi a_w_soap_meal_bi a_w_treat_water a_w_toilet_sweep_bi
	local a_Ebeh1 a_Em_soap_toilet_bi a_Em_soap_meal_bi a_Ew_soap_toilet_bi a_Ew_soap_meal_bi a_Ew_treat_water a_Ew_toilet_sweep_bi a_Ew_toilet_improv
	egen aste_beh1 = rowmean(`a_beh1')  
	egen Easte_beh1 = rowmean(`a_Ebeh1')  
	
	** Column 4: Overall health ASTE
	
	egen aste_beh0 = rowmean(`a_beh1' `a_beh2' `a_beh3')  
	egen Easte_beh0 = rowmean(`a_Ebeh1' `a_Ebeh2' `a_Ebeh3') 

	* Normalize ASTEs so that SD=1
	
	foreach var in aste_beh1 Easte_beh1 aste_beh2 Easte_beh2 aste_beh3 Easte_beh3 aste_beh0 Easte_beh0 {
		sum `var' if control==1
		replace `var'=(`var'-`r(mean)')/`r(sd)'				
	}	
	
	**** REGRESSIONS: Table 3, Health Behaviors ****
	
	estimates clear
	local controls district? 
	local covars wemp whn mhn
	lab var wemp "WCommHN"
	
	foreach y in aste_beh2 { // newborn health: column (1)
	mdesc E`y' `y' `covars' `controls'
		eststo est`y': areg E`y' `y' `covars' `controls', absorb(stratum) cluster(villageid)		
		sum E`y' if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`y'
		test whn=wemp
			estadd scalar pval1=r(p): est`y'
		test wemp=mhn
			estadd scalar pval2=r(p): est`y'
		test whn=mhn
			estadd scalar pval3=r(p): est`y'	
	}
	foreach y in aste_beh3 aste_beh1 aste_beh0 { // maternal health, hygiene, overall ASTE: columns (2), (3), (4)
		eststo est`y': areg E`y' `y' `covars' `controls', absorb(stratum) cluster(villageid)		
		sum E`y' if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`y'
		test whn=wemp
			estadd scalar pval1=r(p): est`y'
		test wemp=mhn
			estadd scalar pval2=r(p): est`y'
		test whn=mhn
			estadd scalar pval3=r(p): est`y'	
	}
	
	#delimit ;
	esttab using "$tables/table_3.tex", 
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs style(tex) 
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none)
		order(wemp whn mhn) prehead(" { \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
		\begin{tabular}{l*{4}{c}} \toprule \toprule 
		&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)} &\multicolumn{1}{c}{(4)} \\ 
		\midrule
		&\multicolumn{1}{c}{Newborn}&\multicolumn{1}{c}{Maternal}&\multicolumn{1}{c}{Sanitary}&\multicolumn{1}{c}{Overall}\\ 
		&\multicolumn{1}{c}{health}&\multicolumn{1}{c}{health}&\multicolumn{1}{c}{practices}&\multicolumn{1}{c}{health}\\ 
		&\multicolumn{1}{c}{ASTE}&\multicolumn{1}{c}{ASTE}&\multicolumn{1}{c}{ASTE}&\multicolumn{1}{c}{ASTE}\\ 
		\midrule") 
		posthead(" ")	
		postfoot("\bottomrule \bottomrule \end{tabular} }")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean of outcome" " "  "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f  %20s  %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr		

	** SAVE BASELINE INDICES HERE FOR BASELINE CHECKS TABLE BELOW
	
	keep id aste_beh2 aste_beh3 aste_beh1 aste_beh0
	save "$intermediate\baseline_aste_beh_tab3", replace
	}

*===============================================================================*
* Table 4: Program impacts on women's and children's nutrition.
*===============================================================================*	

	if `table_4' == 1 {	
		
	use "$analysis/womens_mens_mcm.dta", clear
	
	tab districtid, gen(district)
	drop district4	
	
	eststo clear
	estimates clear

	*** Panel A: FOOD INTAKE (WOMEN AND CHILDREN)
			
	** Generate standardized variables for ASTE indices (WOMEN):
			
	foreach var in w_milk w_water w_tea w_juice w_otherbev w_matooke w_roots w_grains w_organ w_meat w_egg w_fish w_green w_pump w_otherfru {
	cap confirm variable B`var', exact
	if !_rc {
			drop B`var'
	}
	cap confirm variable EE`var', exact
	if !_rc {
			drop EE`var'
	}	
		sum `var' if control == 1
		gen B`var'=(`var'-`r(mean)')/`r(sd)'
		sum E`var' if control == 1
		gen EE`var'=(E`var'-`r(mean)')/`r(sd)'
	}	
		
	preserve
		use "$analysis/child_level_mcm.dta", clear
		
		tab districtid, gen(district)
		drop district4	
		
		collapse (mean) Emilk Ewater Etea Ejuice Eotherbev Ematooke Eroots Egrains Eorgan Emeat Ebeans Eegg Efish Egreen Epump Eotherfru ///
			milk water tea juice otherbev matooke roots grains organ meat beans egg fish green pump otherfru, by(id) 	
		
		save "$intermediate\foraste.dta", replace
	restore 
	
	merge 1:1 id using "$intermediate\foraste.dta", keep(match) nogen
	
	** Generate standardized variables for ASTE indices (CHILDREN):
			
	foreach var in milk water tea juice otherbev matooke roots grains organ meat egg fish green pump otherfru {
	cap confirm variable B`var', exact
	if !_rc {
			drop B`var'
	}
	cap confirm variable EE`var', exact
	if !_rc {
			drop EE`var'
	}		
		sum `var' if control == 1
		gen B`var'=(`var'-`r(mean)')/`r(sd)'
		sum E`var' if control == 1
		gen EE`var'=(E`var'-`r(mean)')/`r(sd)'
	}	
			
		*1) Beverages ASTE: WOMEN + CHILDREN
	
	cap drop bev_aste Ebev_aste			
	egen bev_aste = rowmean(Bmilk Bwater Btea Bjuice Botherbev Bw_milk Bw_water Bw_tea Bw_juice Bw_otherbev)	
	egen Ebev_aste = rowmean(EEmilk EEwater EEtea EEjuice EEotherbev EEw_milk EEw_water EEw_tea EEw_juice EEw_otherbev)		
		
		*2) Carbohydrates ASTE
		
	cap drop carb_aste Ecarb_aste	
	egen carb_aste = rowmean(Bmatooke Broots Bgrains Bw_matooke Bw_roots Bw_grains)	
	egen Ecarb_aste = rowmean(EEmatooke EEroots EEgrains EEw_matooke EEw_roots EEw_grains)		

		*3) Protein-rich foods ASTE
	
	cap drop protein_aste Eprotein_aste			
	egen protein_aste = rowmean(Borgan Bmeat Begg Bfish Bw_organ Bw_meat Bw_egg Bw_fish)	
	egen Eprotein_aste = rowmean(EEorgan EEmeat EEegg EEfish EEw_organ EEw_meat EEw_egg EEw_fish)		
	
		*4) Fruit and Veg ASTE
	
	cap drop fruitveg_aste Efruitveg_aste	
	egen fruitveg_aste = rowmean(Bgreen Bpump Botherfru Bw_green Bw_pump Bw_otherfru)	
	egen Efruitveg_aste = rowmean(EEgreen EEpump EEotherfr EEw_green EEw_pump EEw_otherfr)		

	* Normalize ASTEs so that SD=1
	foreach var in carb_aste protein_aste fruitveg_aste {
		sum `var' if control==1
		replace `var'=(`var'-`r(mean)')/`r(sd)'				
		sum E`var' if control==1
		replace E`var'=(E`var'-`r(mean)')/`r(sd)'				
	}	
		
	eststo clear
	estimates clear
	
	local controls district? 
	local covars wemp whn mhn
	lab var wemp "WCommHN"
	
	foreach y in carb_aste protein_aste fruitveg_aste {
		eststo est`y': areg E`y' `covars' `controls' `y', absorb(stratum) cluster(villageid)		
		sum E`y' if e(sample)==1 & control==1 
		local num1: display %4.3f `r(mean)'
			estadd local mean "`num1'": est`y'
		local num2: display %4.3f `r(sd)'
			estadd local sd "(`num2')": est`y'
		test whn=wemp
		local pval1: display %4.3f `r(p)'
			estadd local p1 "`pval1'": est`y'
		test wemp=mhn
		local pval2: display %4.3f `r(p)'
			estadd local p2 "`pval2'": est`y'
		test whn=mhn
		local pval3: display %4.3f `r(p)'
			estadd local p3 "`pval3'": est`y'
	}
		
	** Output results to Panel A, Table 4 (FOOD RECALL: Woman + Children)
	
	#delimit ;
	esttab using "$tables/table_4.tex", 
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs style(tex) 
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none)
		order(wemp whn mhn) prehead(" { \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
		\begin{tabular}{l*{3}{c}} \toprule \toprule 
		&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}   \\ 
		\midrule
		& Carbohydrates & Animal-sourced & Fruit \& veg \\
		& ASTE & foods ASTE & ASTE\\
		\midrule")
		posthead("&\multicolumn{3}{c}{\textbf{Panel A: Food Intake (Women and Children)}} \\ \cmidrule(lr){2-4}")
		postfoot("\midrule")
		stats(mean sd p1 p2 p3 N, 
		labels("Control mean of outcome" " " "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f %20s %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr	

	** SAVE BASELINE INDICES HERE FOR BASELINE CHECKS TABLE BELOW
	
	keep id carb_aste protein_aste fruitveg_aste 
	save "$intermediate\baseline_aste_food_exp_tab4", replace
	
	eststo clear
	estimates clear

		*** Panel B: Food Expenditure and Crop Allocation

	use "$analysis/womens_mens_mcm.dta", clear
	
	tab districtid, gen(district)
	drop district4	
	
	eststo clear
	estimates clear
	
	** Crop rotation on plots
	
	cap drop Ew_growmoreveg_12mo
	gen Ew_growmoreveg_12mo = Ew_change_crops_how1
	replace Ew_growmoreveg_12mo = 0 if Ew_change_crops == 0 // if HH didn't change crop composition in the last 12 months, they are not growing more fruit and veg
	
	** Expenditure
	
	*endline headcount
	cap drop Ehh_num_member 
	recode Ew_num_adults (18=.) // plausible outlier
	gen Ehh_num_member = Ew_num_adults + 0.5*Em_hhkids_num // Em_hhkids_num: only from men's endline survey: num kids w/ bl wife who live in HH
	
	*baseline headcount
	cap drop hh_num_member
	gen hh_num_member = w_num_adults + 0.5*w_numkids18

	*endline spending
	foreach y in meats rice {
		cap drop Ew_exp_`y'		
		gen Ew_exp_`y' = Ew_last7d_`y'/Ehh_num_member
	}	
	cap drop Ew_exp_protein
	ren Ew_exp_meats Ew_exp_protein // "meats" designates meat and fish
	
	*baseline spending
	cap drop w_exp_protein w_exp_rice	
	gen w_exp_protein = w_mtfs_own/hh_num_member	
	gen w_rice_7d = (w_last6m_rice/181) * 7 // convert expenditure in last 6mo to how much was spent in last 7d
	gen w_exp_rice = w_rice_7d/hh_num_member	
	
	*trim top 1% of expenditure values
	foreach y in rice protein  {
		sum w_exp_`y', d
		replace w_exp_`y' = . if w_exp_`y'>`r(p99)'
		sum Ew_exp_`y', d
		replace Ew_exp_`y' = . if Ew_exp_`y'>`r(p99)'
	}
	
	local controls 	district? 
	local covars wemp whn mhn
	lab var wemp "WCommHN"
	
	foreach y in w_exp_rice w_exp_protein {
		eststo est`y': areg E`y' `covars' `controls' `y', absorb(stratum) cluster(villageid)	
		sum E`y' if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`y'
		test whn=wemp
		local pval1: display %4.3f `r(p)'
			estadd local p1 "`pval1'": est`y'
		test wemp=mhn
		local pval2: display %4.3f `r(p)'
			estadd local p2 "`pval2'": est`y'
		test whn=mhn
		local pval3: display %4.3f `r(p)'
			estadd local p3 "`pval3'": est`y'
	}

	foreach y in w_growmoreveg_12mo {
		eststo est`y': areg E`y' `covars' `controls', absorb(stratum) cluster(villageid)	
		sum E`y' if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`y'
		test whn=wemp
		local pval1: display %4.3f `r(p)'
			estadd local p1 "`pval1'": est`y'
		test wemp=mhn
		local pval2: display %4.3f `r(p)'
			estadd local p2 "`pval2'": est`y'
		test whn=mhn
		local pval3: display %4.3f `r(p)'
			estadd local p3 "`pval3'": est`y'
	}
	
	#delimit ;
	esttab using "$tables/table_4.tex", 
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets append gaps label booktabs style(tex) 
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none)
		order(wemp whn mhn) prehead(" 
		& Rice & Meat/fish & Grows more \\
		& exp pc & exp pc & fruit/veg \\
		\midrule") 
		posthead("&\multicolumn{3}{c}{\textbf{Panel B: Food Expenditure and Crop Allocation}} \\ \cmidrule(lr){2-4}")
		postfoot("\bottomrule \bottomrule \end{tabular} }")
		stats(mean sd p1 p2 p3 N, 
		labels("Control mean of outcome" " "  "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f  %20s  %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr	
		
	}	


*===============================================================================*
* Table 5: Program impacts on child health outcomes.
*===============================================================================*	

	if `table_5' == 1 {
		
	use "$analysis/child_level_mcm.dta", clear
	
	** stunting rate in sample at baseline: 
	sum lhfa_neg2 // .3668662
	sum age if lhfa_neg2!=. // 0-28 months
	
	tab districtid, gen(district)
	drop district4	

	estimates clear
	eststo clear
	
	** clean up age variables
	
	cap drop birthyear birthmonth
	gen birthyear=year(birthdate)
	gen birthmonth=month(birthdate)
	
	* recode missing values in endline age based on birth month and year: 	
	gen flag_Eage=1 if inlist(Eage,999,.)
	replace Eage = Eanthro_date - birthdate if flag_Eage==1
	replace Eage = Eage*(12/365) if flag_Eage==1 
	drop flag_Eage
	replace Eage=. if Eage-age>30 & age!=. 
	replace Eage=round(Eage)
	
	* generate variable = child's age at the start of the intervention (February 2013)
	cap drop month day year february2013 age_start_t
	
	gen month=2
	gen day=1
	gen year=2013
	gen february2013 = mdy(month, day, year)
	format february2013 %td
	lab var february2013 "Start of intervention: February 2013"
	drop month day year
	gen month=11
	gen day=1
	gen year=2013
	gen november2013 = mdy(month, day, year)
	format november2013 %td
	lab var november2013 "End of intervention: November 2013"
	drop month day year
	
	gen age_start_t = february2013 - birthdate
	gen age_start_t_days = age_start_t
	lab var age_start_t_days "Age of child (in days) at the start of the intervention"	
	replace age_start_t = age_start_t*(12/365) 
	replace age_start_t = round(age_start_t) 
	lab var age_start_t "Age of child (in months) at the start of the intervention"	
	
	gen age_end_t = november2013 - birthdate
	replace age_end_t = age_end_t*(12/365) 
	replace age_end_t=round(age_end_t)
	lab var age_end_t "Age of child (in months) at the end of the intervention"	
		
	eststo clear
	estimates clear

	local controls 	district? 
	local covars wemp whn mhn
	lab var wemp "WCommHN"	
	
	** weight-for-age: all children aged 23 months or less at the start of the intervention
	foreach y in wfa {	
		eststo estimation`y': reghdfe E`y' `covars' `controls' female if age_start_t<=23, absorb(stratum Eage age_start_t) cluster(villageid)	
		sum E`y' if e(sample)==1 & control==1 & age_start_t<=23
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimation`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimation`y'
		test whn=wemp
			estadd scalar pval1 = r(p): estimation`y'
		test wemp=mhn
			estadd scalar pval2 = r(p): estimation`y'
		test whn=mhn
			estadd scalar pval3 = r(p): estimation`y'		
	}
	
	** height-for-age: all children aged 23 months or less at the start of the intervention
	foreach y in lhfa {	
		eststo estimation`y': reghdfe E`y' `covars' `controls' female Eheight_how if age_start_t<=23, absorb(stratum Eage age_start_t) cluster(villageid)	
		sum E`y' if e(sample)==1 & control==1 & age_start_t<=23
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimation`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimation`y'
		test whn=wemp
			estadd scalar pval1 = r(p): estimation`y'
		test wemp=mhn
			estadd scalar pval2 = r(p): estimation`y'
		test whn=mhn
			estadd scalar pval3 = r(p): estimation`y'		
	}
	
	** birth weight 
	gen Ebweight_kg = Ebirth_weight
	sum Ebweight_kg, d
	replace Ebweight_kg = . if Ebweight_kg>5 // trimming top 5% of values

	foreach y in bweight_kg {
		eststo estimation`y': reghdfe E`y' `covars' `controls' female Eweight_immcard if age_start_t_days<=-28 & onlyin==2, absorb(stratum age_start_t) cluster(villageid) // sample restricted to babies born since the start of the intervention
		sum E`y' if e(sample)==1 & control==1 & age_start_t_days<=-28 & onlyin==2
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimation`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimation`y'
		test whn=wemp
			estadd scalar pval1 = r(p): estimation`y'
		test wemp=mhn
			estadd scalar pval2 = r(p): estimation`y'
		test whn=mhn
			estadd scalar pval3 = r(p): estimation`y'		
	}
	
	** Output results to TABLE 5
	#delimit ;
	esttab using "$tables/table_5.tex", 
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs style(tex) 
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none)
		order(wemp whn mhn) prehead(" { \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
		\begin{tabular}{l*{3}{c}} \toprule \toprule 
		&\multicolumn{1}{c}{(1)} &\multicolumn{1}{c}{(2)} &\multicolumn{1}{c}{(3)}  \\ 
		\midrule
		& Weight-for-age & Height-for-age & Birth weight \\
		& Z-score        & Z-score 		  & (KGs) 		\\
		\midrule")
		posthead(" ")
		postfoot("\bottomrule\bottomrule \end{tabular} }")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean of outcome" " " "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f %20s %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr	
	}
	
*===============================================================================*			
* Table A.1: Balance Checks.
*===============================================================================*		

	if `table_a1' == 1 {
	
	use "$analysis/womens_mens_mcm.dta", clear	
	
	** WOMAN-LEVEL OUTCOMES: MERGE IN BASELINE VALUES OF ENDLINE ASTE INDICES 
	
	cap drop aste_* 
	cap drop *aste
	cap drop *knowl_index
	
	** Table 1 outcomes: decision-making indices + husband violent behavior
	
	merge 1:1 id using "$intermediate\baseline_aste_relationship_tab1", nogen
	
	** Table 2 outcomes: discussion indices
	
	merge 1:1 id using "$intermediate\baseline_aste_discussion_knowledge_tab2", nogen
		
	** Table 3 outcomes: health behavior indices
	
	merge 1:1 id using "$intermediate\baseline_aste_beh_tab3", nogen
	
	** Table 4 outcomes: food recall indices
	
	merge 1:1 id using "$intermediate\baseline_aste_food_exp_tab4", nogen
	
	** add expenditure (un-trimmed)
	
	*baseline headcount
	cap drop hh_num_member
	gen hh_num_member = w_num_adults + 0.5*w_numkids18
	
	*baseline spending
	cap drop w_exp_protein w_exp_rice	
	gen w_exp_protein = w_mtfs_own/hh_num_member	
	gen w_rice_7d = (w_last6m_rice/182) * 7 // convert expenditure in last 6mo to how much was spent in last 7d
	gen w_exp_rice = w_rice_7d/hh_num_member	
						
	label var w_age "Woman's age"
	label var w_educ "Woman's years of education"
	label var w_numkids0to5 "Number of children under 5 years old"
	label var w_inc "Woman earns income"
	label var aste_w_bi "Wife part of household decisions ASTE (Woman)"
	label var aste_w_joint "Couple makes decisions together ASTE (Woman)" 
	label var aste_vbeh_w "Husband's violent behavior ASTE"
	label var w_marcomm_aste "Woman's Overall Discussion ASTE"
	label var w_Hknowl_index "Woman's Health Knowledge ASTE" 
	label var m_Hknowl_index "Man's Health Knowledge ASTE" 
	label var aste_beh1 "Household Sanitary Practices ASTE"
	label var aste_beh2 "Newborn Health ASTE"
	label var aste_beh3 "Maternal Health ASTE"
	label var carb_aste "Carbohydrates ASTE"
	label var protein_aste "Animal-sourced foods ASTE"
	label var fruitveg_aste "Fruit and vegetables ASTE"
	label var w_exp_rice "Spending on rice per capita, last 7 days (UGX)"
	label var w_exp_protein "Spending on meat/fish per capita, last 7 days (UGX)"
		
	** CHILD-LEVEL OUTCOMES
	
	* Birthweight of last-born baby 
	sum w_birth_weight, d
	replace w_birth_weight = . if w_birth_weight>5 // trimming top 5% of values (as in endline)
	
	* impute missing birthweight values with village mean and flag missings: 
	gen w_bweight_mis = w_birth_weight == .
	bys villageid: egen mean_birth_weight = mean(w_birth_weight)
	replace w_birth_weight = mean_birth_weight if w_bweight_mis == 1 
				
	** Now merge woman-level indices with child-level outcomes: 
	preserve
		use "$analysis/child_level_mcm.dta", clear
		keep if age<=28 // anthropometrics were collected for children aged 0-28 months at baseline
		unique id
		** Save only relevant outcomes here for merging
		keep id wfa lhfa mfa c_hblevel flag_*_imp
		tempfile childlevel
		sa `childlevel', replace
	restore
	
	merge 1:m id using `childlevel', nogen 
	*codebook id if _m==1 // 85
	*codebook id if _m==3 // 5427
	
	* To only use one obs per mother
	gen adultdataset=.
	bys id: gen x=_n
	tab x
	replace adultdataset=1 if x == 1
	drop x

	label var w_birth_weight "Birthweight of last-born baby (KG)"
	label var wfa "Child's weight-for-age Z-score"
	label var lhfa "Child's height-for-age Z-score"
	cap label var mfa "Child's MUAC-for-age Z-score"
	cap label var c_hblevel "Child's hemoglobin level (g/dl)"
	
	** save dataset here for use in the attrition table below
	** woman-level variables: 
	preserve
		collapse (first) w_age w_educ w_numkids0to5 w_inc aste_w_bi aste_w_joint aste_vbeh_w w_marcomm_aste w_Hknowl_index m_Hknowl_index aste_beh1 aste_beh2 aste_beh3 carb_aste protein_aste fruitveg_aste w_birth_weight w_bweight_mis w_exp_rice w_exp_protein, by(id)		
		tempfile temp
		save `temp', replace
	restore 
	
	** child-level anthropometric variables: keep non-missings and generate a woman-level aggregate from these
	preserve
		drop if wfa==. & lhfa==. & mfa==. & c_hblevel==.
		collapse (mean) wfa lhfa mfa c_hblevel, by(id)
		merge 1:1 id using `temp', nogen
		save "$intermediate\baseline_characteristics.dta", replace
	restore		
	
	*I. Storing the coefficients	
	
	global DESCVARSCHLD wfa lhfa mfa c_hblevel
	
	foreach var in $DESCVARSCHLD { // note: whenever these child anthropometric variables are missing at baseline, we impute missings with the sample mean, so control for a flag variable in each regression below 
		
		* 1. WCommHN Vs. Control
		clonevar treatvar=wemp 	
		eststo `var'_1, title(""): reg `var' treatvar whn mhn i.stratum i.districtid flag_`var'_imp, vce(cluster villageid)		
		drop treatvar
		
		* 2. WHN Vs. Control			
		clonevar treatvar=whn	
		eststo `var'_2, title(""): reg `var' treatvar wemp mhn i.stratum i.districtid flag_`var'_imp, vce(cluster villageid)
		drop treatvar
		
		* 3. MHN Vs. Control
		clonevar treatvar=mhn 	
		eststo `var'_3, title(""): reg `var' treatvar wemp whn i.stratum i.districtid flag_`var'_imp, vce(cluster villageid)									
		drop treatvar
		
		* 4. WCommHN vs WHN
		clonevar treatvar=wemp		
		eststo `var'_4, title(""): reg `var' treatvar whn mhn i.stratum i.districtid flag_`var'_imp, vce(cluster villageid)	
		test whn = treatvar
		estadd scalar pvalue = r(p): `var'_4	
		drop treatvar		
	}

	*II. Joint significance test 
	
		*Estimates must be recalculated to calculate the joint significance test since the main estimations used clustered standard errors 
	local v=1		
	foreach var in $DESCVARSCHLD {
			
		eststo e`v'_1, title(""): reg `var' whn wemp mhn i.stratum i.districtid
		
	local ++v	
	dis `v'
		}

	*global for variables
	#d;
	global DESCVARS w_age
				    w_educ
					w_numkids0to5
					w_inc
					aste_w_bi
					aste_w_joint
					aste_vbeh_w
					w_marcomm_aste
					w_Hknowl_index 
					m_Hknowl_index
					aste_beh1
					aste_beh2
					aste_beh3
					carb_aste
					protein_aste
					fruitveg_aste
					w_exp_rice 
					w_exp_protein
	;
	#d cr		

	*I. Storing the coefficients	
	foreach var in $DESCVARS {

		* 1. WCommHN Vs. Control
		clonevar treatvar=wemp 	
		eststo `var'_1, title(""): reg `var' treatvar whn mhn i.stratum i.districtid if adultdataset==1 , vce(cluster villageid)											
		test whn = treatvar
		estadd scalar pvalue = r(p): `var'_1	
		drop treatvar
		
		* 2. WHN Vs. Control			
		clonevar treatvar=whn
		eststo `var'_2, title(""): reg `var' treatvar wemp mhn i.stratum i.districtid if adultdataset==1 , vce(cluster villageid)	
		drop treatvar
		
		* 3. MHN Vs. Control
		clonevar treatvar=mhn		
		eststo `var'_3, title(""): reg `var' treatvar wemp whn i.stratum i.districtid if adultdataset==1 , vce(cluster villageid)	
		drop treatvar
		
		* 4. WCommHN vs WHN
		clonevar treatvar=wemp		
		eststo `var'_4, title(""): reg `var' treatvar whn mhn i.stratum i.districtid if adultdataset==1 , vce(cluster villageid)	
		test whn = treatvar
		estadd scalar pvalue = r(p): `var'_4	
		drop treatvar		
	}
	
	*### JANUARY 2024: add birthweight of last baby born in past 2 years at baseline as an outcome (since we have it as an outcome in Table 5), controlling for whether missing variable was imputed: 
		
	* 1. WCommHN Vs. Control
	clonevar treatvar=wemp 	
	eststo w_birth_weight_1, title(""): reg w_birth_weight treatvar whn mhn i.stratum i.districtid w_bweight_mis if adultdataset==1, vce(cluster villageid)											
	test whn = treatvar
	estadd scalar pvalue = r(p): w_birth_weight_1	
	drop treatvar
	
	* 2. WHN Vs. Control			
	clonevar treatvar=whn
	eststo w_birth_weight_2, title(""): reg w_birth_weight treatvar wemp mhn i.stratum i.districtid w_bweight_mis if adultdataset==1, vce(cluster villageid)	
	drop treatvar
	
	* 3. MHN Vs. Control
	clonevar treatvar=mhn		
	eststo w_birth_weight_3, title(""): reg w_birth_weight treatvar wemp whn i.stratum i.districtid w_bweight_mis if adultdataset==1, vce(cluster villageid)	
	drop treatvar
	
	* 4. WCommHN vs WHN
	clonevar treatvar=wemp		
	eststo w_birth_weight_4, title(""): reg w_birth_weight treatvar whn mhn i.stratum i.districtid w_bweight_mis if adultdataset==1, vce(cluster villageid)	
	test whn = treatvar
	estadd scalar pvalue = r(p): w_birth_weight_4	
	drop treatvar
	
	*II. Joint significance test 

		local v : word count $DESCVARSCHLD
		local v=`v'+1
		dis `v'    // Edit local to be the number of child variables + 1
		
		/*Estimates must be recalculated to calculate the joint significance test since the main estimations used clustered standard errors */
		
	foreach var in $DESCVARS {			
		dis `v'    
		eststo e`v'_1, title(""): reg `var' whn wemp mhn i.stratum i.districtid if adultdataset==1 

	local ++v		
	dis `v' 
		}
	
	** Birthweight of last-born baby in last two years (Q: Have you given birth at least once since September 2010?  In other words, did you give birth to a child who would now be two years old or younger?)
	
	eststo e23_1, title(""): reg w_birth_weight whn wemp mhn i.stratum i.districtid w_bweight_mis if adultdataset==1 									
		
		* 1. WCommHN Vs. Control
		suest e1_1 e2_1 e3_1 e4_1 e5_1 e6_1 e7_1 e8_1 e9_1 e10_1 e11_1 e12_1 e13_1 e14_1 e15_1 e16_1 e17_1 e18_1 e19_1 e20_1 e21_1 e22_1 e23_1, cluster(villageid)
			test [e1_1_mean]wemp
			test [e2_1_mean]wemp, accum
			test [e3_1_mean]wemp, accum
			test [e4_1_mean]wemp, accum
			test [e5_1_mean]wemp, accum
			test [e6_1_mean]wemp, accum
			test [e7_1_mean]wemp, accum
			test [e8_1_mean]wemp, accum
			test [e9_1_mean]wemp, accum
			test [e10_1_mean]wemp, accum
			test [e11_1_mean]wemp, accum
			test [e12_1_mean]wemp, accum
			test [e13_1_mean]wemp, accum
			test [e14_1_mean]wemp, accum
			test [e15_1_mean]wemp, accum
			test [e16_1_mean]wemp, accum			
			test [e17_1_mean]wemp, accum			
			test [e18_1_mean]wemp, accum			
			test [e19_1_mean]wemp, accum	
			test [e20_1_mean]wemp, accum	
			test [e21_1_mean]wemp, accum	
			test [e22_1_mean]wemp, accum	
			test [e23_1_mean]wemp, accum	
			
			local ftest_1: di %9.3f `r(p)'
			local ftest_1="`ftest_1'"
			
		* 2. WHN Vs. Control
		suest e1_1 e2_1 e3_1 e4_1 e5_1 e6_1 e7_1 e8_1 e9_1 e10_1 e11_1 e12_1 e13_1 e14_1 e15_1 e16_1 e17_1 e18_1 e19_1 e20_1 e21_1 e22_1 e23_1, cluster(villageid)
			test [e1_1_mean]whn 
			test [e2_1_mean]whn, accum
			test [e3_1_mean]whn, accum
			test [e4_1_mean]whn, accum
			test [e5_1_mean]whn, accum
			test [e6_1_mean]whn, accum
			test [e7_1_mean]whn, accum
			test [e8_1_mean]whn, accum
			test [e9_1_mean]whn, accum
			test [e10_1_mean]whn, accum
			test [e11_1_mean]whn, accum
			test [e12_1_mean]whn, accum
			test [e13_1_mean]whn, accum
			test [e14_1_mean]whn, accum
			test [e15_1_mean]whn, accum
			test [e16_1_mean]whn, accum			
			test [e17_1_mean]whn, accum			
			test [e18_1_mean]whn, accum			
			test [e19_1_mean]whn, accum	
			test [e20_1_mean]whn, accum	
			test [e21_1_mean]whn, accum	
			test [e22_1_mean]whn, accum	
			test [e23_1_mean]whn, accum	
			
			local ftest_2: di %9.3f `r(p)'
			local ftest_2="`ftest_2'"
			
		* 3. MHN Vs. Control
		suest e1_1 e2_1 e3_1 e4_1 e5_1 e6_1 e7_1 e8_1 e9_1 e10_1 e11_1 e12_1 e13_1 e14_1 e15_1 e16_1 e17_1 e18_1 e19_1 e20_1 e21_1 e22_1 e23_1, cluster(villageid)
			test [e1_1_mean]mhn 
			test [e2_1_mean]mhn, accum
			test [e3_1_mean]mhn, accum
			test [e4_1_mean]mhn, accum
			test [e5_1_mean]mhn, accum
			test [e6_1_mean]mhn, accum
			test [e7_1_mean]mhn, accum
			test [e8_1_mean]mhn, accum
			test [e9_1_mean]mhn, accum
			test [e10_1_mean]mhn, accum
			test [e11_1_mean]mhn, accum
			test [e12_1_mean]mhn, accum
			test [e13_1_mean]mhn, accum
			test [e14_1_mean]mhn, accum
			test [e15_1_mean]mhn, accum
			test [e16_1_mean]mhn, accum			
			test [e17_1_mean]mhn, accum			
			test [e18_1_mean]mhn, accum			
			test [e19_1_mean]mhn, accum				
			test [e20_1_mean]mhn, accum				
			test [e21_1_mean]mhn, accum				
			test [e22_1_mean]mhn, accum	
			test [e23_1_mean]mhn, accum	
			
			local ftest_3: di %9.3f `r(p)'
			local ftest_3="`ftest_3'"								
			
		* WCommHN - WHN	
		suest e1_1 e2_1 e3_1 e4_1 e5_1 e6_1 e7_1 e8_1 e9_1 e10_1 e11_1 e12_1 e13_1 e14_1 e15_1 e16_1 e17_1 e18_1 e19_1 e20_1 e21_1 e22_1 e23_1, cluster(villageid)		
			test [e1_1_mean]wemp = [e1_1_mean]whn 
			test [e2_1_mean]wemp = [e2_1_mean]whn, accum 
			test [e3_1_mean]wemp = [e3_1_mean]whn, accum 
			test [e4_1_mean]wemp = [e4_1_mean]whn, accum 
			test [e5_1_mean]wemp = [e5_1_mean]whn, accum 
			test [e6_1_mean]wemp = [e6_1_mean]whn, accum 
			test [e7_1_mean]wemp = [e7_1_mean]whn, accum 
			test [e8_1_mean]wemp = [e8_1_mean]whn, accum 
			test [e9_1_mean]wemp = [e9_1_mean]whn, accum 
			test [e10_1_mean]wemp = [e10_1_mean]whn, accum 
			test [e11_1_mean]wemp = [e11_1_mean]whn, accum 
			test [e12_1_mean]wemp = [e12_1_mean]whn, accum 
			test [e13_1_mean]wemp = [e13_1_mean]whn, accum 
			test [e14_1_mean]wemp = [e14_1_mean]whn, accum 
			test [e15_1_mean]wemp = [e15_1_mean]whn, accum 
			test [e16_1_mean]wemp = [e16_1_mean]whn, accum 
			test [e17_1_mean]wemp = [e17_1_mean]whn, accum 
			test [e18_1_mean]wemp = [e18_1_mean]whn, accum 
			test [e19_1_mean]wemp = [e19_1_mean]whn, accum 
			test [e20_1_mean]wemp = [e20_1_mean]whn, accum 
			test [e21_1_mean]wemp = [e21_1_mean]whn, accum 
			test [e22_1_mean]wemp = [e22_1_mean]whn, accum 
			test [e23_1_mean]wemp = [e23_1_mean]whn, accum 
			
			local ftest_4: di %9.3f `r(p)'
			local ftest_4="`ftest_4'"	
	
			
	*  WHN - MHN
		suest e1_1 e2_1 e3_1 e4_1 e5_1 e6_1 e7_1 e8_1 e9_1 e10_1 e11_1 e12_1 e13_1 e14_1 e15_1 e16_1 e17_1 e18_1 e19_1 e20_1 e21_1 e22_1 e23_1, cluster(villageid)		
			test [e1_1_mean]mhn = [e1_1_mean]whn 
			test [e2_1_mean]mhn = [e2_1_mean]whn, accum 
			test [e3_1_mean]mhn = [e3_1_mean]whn, accum 
			test [e4_1_mean]mhn = [e4_1_mean]whn, accum 
			test [e5_1_mean]mhn = [e5_1_mean]whn, accum 
			test [e6_1_mean]mhn = [e6_1_mean]whn, accum 
			test [e7_1_mean]mhn = [e7_1_mean]whn, accum 
			test [e8_1_mean]mhn = [e8_1_mean]whn, accum 
			test [e9_1_mean]mhn = [e9_1_mean]whn, accum 
			test [e10_1_mean]mhn = [e10_1_mean]whn, accum 
			test [e11_1_mean]mhn = [e11_1_mean]whn, accum 
			test [e12_1_mean]mhn = [e12_1_mean]whn, accum 
			test [e13_1_mean]mhn = [e13_1_mean]whn, accum 
			test [e14_1_mean]mhn = [e14_1_mean]whn, accum 
			test [e15_1_mean]mhn = [e15_1_mean]whn, accum 
			test [e16_1_mean]mhn = [e16_1_mean]whn, accum 
			test [e17_1_mean]mhn = [e17_1_mean]whn, accum 
			test [e18_1_mean]mhn = [e18_1_mean]whn, accum 
			test [e19_1_mean]mhn = [e19_1_mean]whn, accum 
			test [e20_1_mean]mhn = [e20_1_mean]whn, accum 
			test [e21_1_mean]mhn = [e21_1_mean]whn, accum 
			test [e22_1_mean]mhn = [e22_1_mean]whn, accum 
			test [e23_1_mean]mhn = [e23_1_mean]whn, accum 
			
			local ftest_5: di %9.3f `r(p)'
			local ftest_5="`ftest_5'"
			
	dis "`ftest_4'"
	dis "`ftest_5'"
	dis `ftest_1'
	dis `ftest_2'
	dis `ftest_3'
	dis `ftest_4'
	
	* Adding F-stat as aux statistic to the last variable presented in the table

	forvalues i=1/4 {
		estimates restore c_hblevel_`i'
		estadd local fjoint="ftest_`i'"
	}

		eststo drop e*
	
	*III. Adding summary statistics
		foreach var in $DESCVARS w_birth_weight {
			* Number of observations
				estimates restore `var'_1	
					mat b=e(b)
					summ `var' if adultdataset==1
					local mean: di %9.0f `r(N)'
					mat b =`mean'
					mat colnames b= "treatvar"
					ereturn post b
					eststo `var'_n		
					mat drop _all
			* Mean
				estimates restore `var'_1	
					mat b=e(b)
					summ `var' 	if adultdataset==1 & control==1 
					local mean: di %9.3f `r(mean)'
					local sd: di %9.3f `r(sd)'
					mat b =`mean'
					mat colnames b= "treatvar"
					ereturn post b
					eststo `var'_m		
					mat drop _all			
			* Standard deviation
				estimates restore `var'_1	
					mat b=e(b)
					summ `var' 	if adultdataset==1 & control==1 
					local sd: di %9.3f `r(sd)'
					mat b =`sd'
					mat colnames b= "treatvar"
					ereturn post b
					eststo `var'_sd		
					mat drop _all	
			* Test WHN = WEMP
				estimates restore `var'_4	
					mat b=e(b)
					test whn = treatvar
					local pvalue: di %9.3f `r(p)'
					mat b = `pvalue'
					mat colnames b= "treatvar"
					ereturn post b
					eststo `var'_p		
					mat drop _all				
		}				
		
	*III. Adding summary statistics
		foreach var in $DESCVARSCHLD {
			* Number of observations
				estimates restore `var'_1	
					mat b=e(b)
					summ `var' 
					local mean: di %9.0f `r(N)'
					mat b =`mean'
					mat colnames b= "treatvar"
					ereturn post b
					eststo `var'_n		
					mat drop _all
			* Mean
				estimates restore `var'_1	
					mat b=e(b)
					summ `var' 	if  control==1 
					local mean: di %9.3f `r(mean)'
					mat b =`mean'
					mat colnames b= "treatvar"
					ereturn post b
					eststo `var'_m		
					mat drop _all	
			* Standard deviation
				estimates restore `var'_1	
					mat b=e(b)
					summ `var' 	if control==1 
					local sd: di %9.3f `r(sd)'
					mat b =`sd'
					mat colnames b= "treatvar"
					ereturn post b
					eststo `var'_sd		
					mat drop _all		
			* Test WHN = WEMP
				estimates restore `var'_4	
					mat b=e(b)
					test whn = treatvar
					local pvalue: di %9.3f `r(p)'
					mat b = `pvalue'
					mat colnames b= "treatvar"
					ereturn post b
					eststo `var'_p		
					mat drop _all						
			}		

	#d ;
	local frame "{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\renewcommand{\arraystretch}{rowspace}  
		\begin{tabular}{{>{\hangindent=1em}p{first}P{0.95cm}P{0.75cm}}*{colno}{>{\centering\arraybackslash}m{colspace}}}
		\toprule";
	#d cr	

	* Layout options
	local frame0 = subinstr("`frame'", "first", "8cm", .) // first column width
	local frame1 = subinstr("`frame0'", "colspace", "1.3cm", .) // column spacing 
	local frame2 = subinstr("`frame1'", "rowspace", "1.2", .) // row spacing
	local prehead = subinstr("`frame2'", "colno", "10", .)	// number of columns (in this case - 2 because the last two have a fixed width)	
	
	dis "`prehead'"
	
	foreach var in $DESCVARS w_birth_weight $DESCVARSCHLD {
			
		* Table head options	
		if "`var'"=="w_age" {
		#d; 
		local head_opt prehead("`prehead' 
		& \multicolumn{2}{c}{Control} & \multicolumn{2}{c}{WCommHN} & \multicolumn{2}{c}{WHN} & \multicolumn{2}{c}{MHN} & WCommHN - WHN & N \\ 
		\cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7}\cmidrule(lr){8-9} & Mean & SD & Coeff. & SE & Coeff. & SE & Coeff. & SE & \textit{p}-value & \\ 
		& (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) & (9) & (10) \\ ")  nonumbers replace
		;
		#d cr		
		}
		else {
			local head_opt frag  nonumbers nolines  append			
		}
			local panel_opt
		
		* Table footer
		if "`var'"=="c_hblevel" {
			local footer_opt postfoot("\bottomrule" "\end{tabular}" "}") 
		}
		else {
			local footer_opt postfoot(" ")
		}
		
		#d; 
		esttab   `var'_m `var'_sd `var'_1 `var'_2 `var'_3  `var'_p `var'_n	using "$tables/appendix_tableA0_balancetest_temp.tex", 
		style(tex) 
		booktabs star(* .1 ** .05 *** .01) se parentheses 
		nonotes nomtitles collabels(none)  nobaselevels substitute(".000         &            \\" " \\" "&            &" "&")
		cells("b(fmt(3) star) se(fmt(3)  par)") noobs	
		keep(treatvar) coeflabel(treatvar "`: var label `var''") `head_opt' `panel_opt' `footer_opt'
		;
		#d cr			
		}	
	* Add Joint significance test 
		sleep 1000
		cap erase "$tables/appendix_tableA0_balancetest.tex"
		cap erase "$tables/table_A1.tex"
		sleep 1000
		filefilter "$tables/appendix_tableA0_balancetest_temp.tex" "$tables/table_A1.tex", from("\BSbottomrule") to("\BShline P-value of joint F-test &&&`ftest_1'&&`ftest_2'&&`ftest_3'&&`ftest_4'& \BS\BS \BSbottomrule")
		sleep 1000
	 erase "$tables/appendix_tableA0_balancetest_temp.tex"
	}
	
*===============================================================================*			
* Table A.2a: Sample attrition by treatment arm.
*===============================================================================*		
	
	if `table_a2a' == 1 {
		
		** MEN AND WOMEN 
	
	use "$analysis/womens_mens_mcm.dta", clear	
	
	tab districtid, gen(district)
	drop district4 

	estimates clear
	
	local covars wemp whn mhn
	local controls district? 
	lab var wemp "WCommHN"
	
	*** REGRESSIONS 
	
	** 1) DIFFERENTIAL ATTRITION BY TREATMENT ARM?
	
	foreach i in women anthro {
		eststo est`i'1: reghdfe sample_`i' wemp whn mhn `controls', a(stratum) cluster(villageid)
		sum sample_`i' if e(sample)==1 & whn==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`i'1
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`i'1
		test whn=wemp
			estadd scalar pval1 = r(p): est`i'1
		test wemp=mhn
			estadd scalar pval2 = r(p): est`i'1
		test whn=mhn
			estadd scalar pval3 = r(p): est`i'1
	}	
	
	#delimit ;
	esttab using "$tables/table_A2a.tex", 
	b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs style(tex) 
		keep(wemp whn mhn) 	
		order(wemp whn mhn) 	
		collabels(, none) mlabels(,none) eqlabel(,none)
		prehead("{ \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
		\begin{tabular}{l*{2}{c}} \toprule \toprule
		& \multicolumn{2}{c}{Still in sample} \\
		\cmidrule(lr){2-3} & Woman & Child anthropometrics  \\ 
		&\multicolumn{1}{c}{(1)} &\multicolumn{1}{c}{(2)}  \\ 
		\midrule") 
		postfoot("\bottomrule \bottomrule \end{tabular} }") posthead(" ")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean of outcome" " " "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f  %20s %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr		
		
	}
		
*==============================================================================================*			
* Table A.2b: Heterogeneity of attrition from the endline survey by baseline characteristics.
*==============================================================================================*			

	if `table_a2b' == 1 {
	
	** MEN AND WOMEN 
	
	use "$analysis/womens_mens_mcm.dta", clear	
	
	tab districtid, gen(district)
	drop district4 

	estimates clear
	
	local covars wemp whn mhn
	local controls district? 

	** merge with baseline characteristics 
	
	drop w_birth_weight // to be replaced with the recoded version of the variable in the baseline data we merge below
	merge 1:1 id using "$intermediate\baseline_characteristics.dta", nogen
	
	lab var wemp "WCommHN"
	
	gen group=0 if control==1
	replace group=1 if whn==1
	replace group=2 if wemp==1
	replace group=3 if mhn==1	
	lab define TREATMENT_ARM 0 "Control" 1 "WHN" 2 "WCommHN" 3"MHN"
	lab values group TREATMENT_ARM
	
	** DIFFERENTIAL ATTRITION BY TREATMENT ARM X BASELINE CHARAC
	
	estimates clear
	
	local baseline_chara w_age w_educ w_numkids0to5 w_inc aste_w_bi aste_w_joint aste_vbeh_w w_marcomm_aste w_Hknowl_index m_Hknowl_index aste_beh1 aste_beh2 aste_beh3 carb_aste protein_aste fruitveg_aste w_birth_weight w_exp_rice w_exp_protein wfa lhfa mfa c_hblevel w_bweight_mis 
		
	*** WOMEN'S SAMPLES: COLUMNS 1-6
	
	foreach i in women {

	** WCommHN vs. WHN 
			
		eststo est`i'1: reghdfe sample_`i' wemp `controls' if wemp==1 | whn==1, a(stratum) cluster(villageid)
		sum sample_`i' if e(sample)==1 & whn==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`i'1
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`i'1
		
		cap drop treatX*
		foreach var in `baseline_chara' {
				gen treatX`var'=wemp*`var' 
			}

		eststo est`i'2: reghdfe sample_`i' wemp treatX* `baseline_chara' `controls' if wemp==1 | whn==1, a(stratum) cluster(villageid)
		sum sample_`i' if e(sample)==1 & whn==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`i'2
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`i'2		
		testparm treatX*
			estadd scalar pval = r(p): est`i'2
			
	** WHN vs. Control

		eststo est`i'3: reghdfe sample_`i' whn `controls' if whn==1 | control==1, a(stratum) cluster(villageid)
		sum sample_`i' if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`i'3
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`i'3

		drop treatX*
		foreach var in `baseline_chara' {
				gen treatX`var'=whn*`var' 
			}
			
		eststo est`i'4: reghdfe sample_`i' whn treatX* `baseline_chara' `controls' if whn==1 | control==1, a(stratum) cluster(villageid)
		sum sample_`i' if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`i'4
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`i'4
		testparm treatX*
			estadd scalar pval = r(p): est`i'4
		
	** WCommHN vs. Control
			
		eststo est`i'5: reghdfe sample_`i' wemp `controls' if wemp==1 | control==1, a(stratum) cluster(villageid)
		sum sample_`i' if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`i'5
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`i'5
		
		drop treatX*
		foreach var in `baseline_chara' {
				gen treatX`var'=wemp*`var' 
			}
		
		eststo est`i'6: reghdfe sample_`i' wemp treatX* `baseline_chara' `controls' if wemp==1 | control==1, a(stratum) cluster(villageid)
		sum sample_`i' if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`i'6
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`i'6
		testparm treatX*
			estadd scalar pval = r(p): est`i'6
	}	

	
	*** COLUMNS 7-12: CHILD ANTHROPOMETRICS SAMPLE
	
	foreach i in anthro {
		
	** WCommHN vs. WHN 
			
		eststo est`i'1: reghdfe sample_`i' wemp `controls' if wemp==1 | whn==1, a(stratum) cluster(villageid)
		sum sample_`i' if e(sample)==1 & whn==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`i'1
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`i'1
		
		cap drop treatX*
		foreach var in `baseline_chara' {
				gen treatX`var'=wemp*`var' 
			}

		eststo est`i'2: reghdfe sample_`i' wemp treatX* `baseline_chara' `controls' if wemp==1 | whn==1, a(stratum) cluster(villageid)
		sum sample_`i' if e(sample)==1 & whn==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`i'2
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`i'2		
		testparm treatX*
			estadd scalar pval = r(p): est`i'2
		
	** WHN vs. Control

		eststo est`i'3: reghdfe sample_`i' whn `controls' if whn==1 | control==1, a(stratum) cluster(villageid)
		sum sample_`i' if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`i'3
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`i'3

		drop treatX*
		foreach var in `baseline_chara' {
				gen treatX`var'=whn*`var' 
			}
			
		eststo est`i'4: reghdfe sample_`i' whn treatX* `baseline_chara' `controls' if whn==1 | control==1, a(stratum) cluster(villageid)
		sum sample_`i' if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`i'4
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`i'4
		testparm treatX*
			estadd scalar pval = r(p): est`i'4
		
	** WCommHN vs. Control
			
		eststo est`i'5: reghdfe sample_`i' wemp `controls' if wemp==1 | control==1, a(stratum) cluster(villageid)
		sum sample_`i' if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`i'5
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`i'5
		
		drop treatX*
		foreach var in `baseline_chara' {
				gen treatX`var'=wemp*`var' 
			}
		
		eststo est`i'6: reghdfe sample_`i' wemp treatX* `baseline_chara' `controls' if wemp==1 | control==1, a(stratum) cluster(villageid)
		sum sample_`i' if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`i'6
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`i'6
		testparm treatX*
			estadd scalar pval = r(p): est`i'6
	}
	
	// Note: we won't report the flag variables (those flagging imputations of missings) in the table		
	
	lab var treatXw_age "Woman's age"
	lab var treatXw_educ "Woman's years of education"
	lab var treatXw_numkids0to5 "Number of children under 5 years old"
	lab var treatXw_inc "Woman earns income"
	lab var treatXaste_w_bi "Woman part of HH decisions ASTE"
	lab var treatXaste_w_joint "Couple makes decisions together ASTE"
	lab var treatXaste_vbeh_w "Husband's violent behavior ASTE"
	lab var treatXw_marcomm_aste "Woman's overall discussion ASTE"
	lab var treatXw_Hknowl_index "Woman's knowledge index ASTE"
	lab var treatXm_Hknowl_index "Man's knowledge index ASTE"
	lab var treatXaste_beh1 "Household Sanitary Practices ASTE"		
	lab var treatXaste_beh2 "Newborn Health ASTE"		
	lab var treatXaste_beh3 "Maternal Health ASTE"		
	lab var treatXcarb_aste "Carbohydrates ASTE"		
	lab var treatXprotein_aste "Animal-sourced foods ASTE"
	lab var treatXfruitveg_aste "Fruit and vegetables ASTE"
	lab var treatXw_exp_rice "Per capita spending on rice, last 7 days (UGX)"
	lab var treatXw_exp_protein "Per capita spending on meat/fish, last 7 days (UGX)"		
	lab var treatXw_birth_weight "Birthweight of last-born baby (KG)"
	lab var treatXwfa "Average child's weight-for-age Z-score"
	lab var treatXlhfa "Average child's height-for-age Z-score"
	lab var treatXmfa "Average child's MUAC-for-age Z-score"
	lab var treatXc_hblevel "Average child's hemoglobin level (g/dl)"	
	
	#d ;
	local frame "{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\renewcommand{\arraystretch}{rowspace}  
		\begin{tabular}{{>{\hangindent=1em}p{first}}*{colno}{>{\centering\arraybackslash}m{colspace}}}
		\toprule";
	#d cr	
	
* Layout options
	local frame0 = subinstr("`frame'", "first", "5.3cm", .) // first column width
	local frame1 = subinstr("`frame0'", "colspace", "1.3cm", .) // column spacing 
	local frame2 = subinstr("`frame1'", "rowspace", "1", .) // row spacing
	local prehead = subinstr("`frame2'", "colno", "12", .)	// number of columns		
			
	#delimit ;
	esttab using "$tables/table_a2b.tex", 
	b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs style(tex) 
		keep(wemp whn treatXw_age treatXw_educ treatXw_numkids0to5 treatXw_inc treatXaste_w_bi treatXaste_w_joint treatXaste_vbeh_w treatXw_marcomm_aste treatXw_Hknowl_index treatXm_Hknowl_index treatXaste_beh1 treatXaste_beh2 treatXaste_beh3 treatXcarb_aste treatXprotein_aste treatXfruitveg_aste treatXw_birth_weight treatXwfa treatXlhfa treatXmfa treatXc_hblevel) 	
		order(wemp whn treatXw_age treatXw_educ treatXw_numkids0to5 treatXw_inc treatXaste_w_bi treatXaste_w_joint treatXaste_vbeh_w treatXw_marcomm_aste treatXw_Hknowl_index treatXm_Hknowl_index treatXaste_beh1 treatXaste_beh2 treatXaste_beh3 treatXcarb_aste treatXprotein_aste treatXfruitveg_aste treatXw_birth_weight treatXwfa treatXlhfa treatXmfa treatXc_hblevel) 	
		collabels(, none) mlabels(,none) eqlabel(,none)
		prehead("`prehead' & \multicolumn{6}{c}{Still in sample: Woman} & \multicolumn{6}{c}{Still in sample: Child anthropometrics} \\
		\cmidrule(lr){2-7} \cmidrule(lr){8-13}
		& \multicolumn{2}{c}{WCommHN vs. WHN} & \multicolumn{2}{c}{WHN vs. Control} & \multicolumn{2}{c}{WCommHN vs. Control} & \multicolumn{2}{c}{WCommHN vs. WHN} & \multicolumn{2}{c}{WHN vs. Control} & \multicolumn{2}{c}{WCommHN vs. Control} \\
		\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(lr){8-9} \cmidrule(lr){10-11} \cmidrule(lr){12-13} 
		&\multicolumn{1}{c}{(1)} &\multicolumn{1}{c}{(2)} &\multicolumn{1}{c}{(3)} &\multicolumn{1}{c}{(4)} &\multicolumn{1}{c}{(5)} &\multicolumn{1}{c}{(6)} &\multicolumn{1}{c}{(7)} &\multicolumn{1}{c}{(8)} &\multicolumn{1}{c}{(9)} &\multicolumn{1}{c}{(10)} &\multicolumn{1}{c}{(11)} &\multicolumn{1}{c}{(12)} \\ 
		\midrule") 
		postfoot("\bottomrule \bottomrule \end{tabular} }") posthead(" ")
		stats(mean pval N, 
		labels("Outcome mean, omitted group" "p-value: joint test" "Observations") 
		fmt(%4.3f %4.3f %9.0fc));
	#delimit cr	
	/* Note: Manually add header just above first interaction term:
	\addlinespace
	\textbf{\textit{WCommHN interacted with:}} \\
	\addlinespace
	*/
	}	
	
*===============================================================================*			
* Table A.3a: Program impacts on effective communication between spouses: Lee bounds.
*===============================================================================*	

	if `table_a3a' == 1 {
{		

	use "$analysis/womens_mens_mcm.dta", clear
	
	tab districtid, gen(district)
	drop district4 
	
	estimates clear
	
	lab var wemp "WCommHN"
	
	*** (1) RELATIONSHIP IMPROVEMENTS
	
	forval i = 1/6 {
		replace Ew_rel_improve`i'=0 if Ew_rel_year_imp==0
		replace Em_rel_improve`i'=0 if Em_rel_year_imp==0
	}
	
	* Generate standardized variables
	foreach var of varlist Ew_rel_improve1-Ew_rel_improve6 Em_rel_improve1-Em_rel_improve6 {
		cap drop A`var'
		sum `var' if control==1
		gen A`var'=(`var'-`r(mean)')/`r(sd)'
	}
	
	* ASTE
	cap drop Ew_rel_improve_aste Em_rel_improve_aste
	egen Ew_rel_improve_aste = rowmean(AEw_rel_improve*)
	egen Em_rel_improve_aste = rowmean(AEm_rel_improve*)
	
	*** (2) WOMAN PART OF DECISION-MAKING

	*** Recoding Household Variables
	** Household Decisions
	* women's reports:
	local HD  w_wmoney w_purch w_savespend w_wcloth w_ccloth w_daily w_chealth w_cfeed w_cschool 
	local EHD Ew_wmoney Ew_purch Ew_savespend Ew_wcloth Ew_ccloth Ew_daily Ew_chealth Ew_cfeed Ew_cschool 
	local HDW w_wmoney w_daily w_chealth w_cfeed   
	local EHDW Ew_wmoney Ew_daily Ew_chealth Ew_cfeed   
	* men's reports:
	local HDM m_wmoney m_daily m_chealth m_cfeed 
	local EHDM Em_wmoney Em_daily Em_chealth Em_cfeed
	
	* define "woman has say" variable as equal to 1 if the woman reports making the decision alone OR jointly with her husband, and 0 otherwise	
	* define "joint decision" variable as equal to 1 if the woman reports making the decision jointly with her husband, and 0 otherwise	
	
	foreach var in `HD' `EHD' `EHDM' {
		replace `var'_bi = `var'_who
		recode `var'_bi (3 = 1) (2 4 5 = 0) (6 99=.)
		gen `var'_joint=`var'_who==3
		replace `var'_joint=. if inlist(`var'_who,6,99)
		replace `var'_joint=. if `var'_bi==.
	}	
	
	foreach var in `HDM' {
		replace `var'_bi = `var'_who
		recode `var'_bi (2 3 = 1) (1 4 5 = 0) (6 99=.)
		gen `var'_joint=`var'_who==3
		replace `var'_joint=. if inlist(`var'_who,6,99)
		replace `var'_joint=. if `var'_bi==.
	}		
	
	*** Women
	** Household Decisions
	local astevarw2 w_wmoney_bi w_daily_bi w_chealth_bi w_cfeed_bi w_savespend_bi w_wcloth_bi w_purch_bi w_cschool_bi w_ccloth_bi 
	local Eastevarw2 Ew_wmoney_bi Ew_daily_bi Ew_chealth_bi Ew_cfeed_bi Ew_savespend_bi Ew_wcloth_bi Ew_purch_bi Ew_cschool_bi Ew_ccloth_bi 
	local astevarw_joint w_wmoney_joint w_daily_joint w_chealth_joint  w_cfeed_joint w_savespend_joint w_wcloth_joint w_purch_joint w_cschool_joint w_ccloth_joint 
	local Eastevarw_joint Ew_wmoney_joint Ew_daily_joint Ew_chealth_joint Ew_cfeed_joint Ew_savespend_joint Ew_wcloth_joint Ew_purch_joint Ew_cschool_joint Ew_ccloth_joint 
	
	*** Men 
	** Household Decisions 
	local astevarm2  m_wmoney_bi  m_daily_bi m_chealth_bi m_cfeed_bi 
	local Eastevarm2 Em_wmoney_bi Em_daily_bi Em_chealth_bi Em_cfeed_bi
	local astevarm_joint m_wmoney_joint m_daily_joint m_chealth_joint m_cfeed_joint 
	local Eastevarm_joint Em_wmoney_joint Em_daily_joint Em_chealth_joint Em_cfeed_joint 
	
	*** ASTE, men's and women's reports
	
	cap drop a_w_*_bi a_Ew_*_bi
	cap drop a_m_*_bi a_Em_*_bi
	
	* Generate standardized variables
	foreach var in `astevarw2' `astevarm2' `astevarw_joint' `astevarm_joint' {
		cap drop a_`var'
		qui sum `var' if control == 1
		gen a_`var'=(`var'-`r(mean)')/`r(sd)'
		cap drop a_E`var'
		qui sum E`var' if control == 1
		gen a_E`var'=(E`var'-`r(mean)')/`r(sd)'
	}
	
	*graph hbar a_w_wmoney_bi a_w_daily_bi a_w_chealth_bi a_w_cfeed_bi a_w_savespend_bi a_w_wcloth_bi a_w_purch_bi a_w_cschool_bi a_w_ccloth_bi	
	*graph hbar a_Ew_wmoney_bi a_Ew_daily_bi a_Ew_chealth_bi a_Ew_cfeed_bi a_Ew_savespend_bi a_Ew_wcloth_bi a_Ew_purch_bi a_Ew_cschool_bi a_Ew_ccloth_bi
	
	foreach y in w m {
		foreach x in bi joint {
			cap drop aste_`y'_`x' Easte_`y'_`x'
			egen aste_`y'_`x' = rowmean(a_`y'_*_`x')
			egen Easte_`y'_`x' = rowmean(a_E`y'_*_`x')
		}
	}
	
	*graph hbar aste_w_bi Easte_w_bi if control==1
	
	*** (3) HUSBAND LESS VIOLENT 

	foreach var in w_humil w_threat w_insult w_beat w_push w_slap w_violent {
		gen `var'_no=1 if `var'freq==3 // no such violence from husband in past year or month
		replace `var'_no=1 if `var'==0 // never been violent in that way
		replace `var'_no=0 if inlist(`var'freq,1,2) // often or sometimes in past year or month
		
		gen E`var'_no=1 if E`var'freq==3 // no such violence from husband in past year or month
		replace E`var'_no=1 if E`var'==0 // never been violent in that way
		replace E`var'_no=0 if inlist(E`var'freq,1,2) // often or sometimes in past year or month
	}
	
	* Generate standardized variables	
	foreach var in w_humil_no w_threat_no w_insult_no w_beat_no w_push_no w_slap_no w_violent_no {
		sum E`var' if control==1
		replace E`var'=(E`var'-`r(mean)')/`r(sd)'
	}
	
	foreach var in w_humil_no w_threat_no w_insult_no w_beat_no w_push_no w_slap_no w_violent_no {
		sum `var' if control==1
		replace `var'=(`var'-`r(mean)')/`r(sd)'
	}
	
	local Evarlist Ew_humil_no Ew_threat_no Ew_insult_no Ew_beat_no Ew_push_no Ew_slap_no Ew_violent_no 
	local varlist w_humil_no w_threat_no w_insult_no w_beat_no w_push_no w_slap_no w_violent_no 
	
	* Generate averaged outcome
	cap drop aste_vbeh_w Easte_vbeh_w
	egen Easte_vbeh_w=rowmean(`Evarlist')
	egen aste_vbeh_w=rowmean(`varlist')
	
	* Normalize all ASTEs so that SD=1
	local astelist w_rel_improve_aste m_rel_improve_aste aste_m_bi aste_m_joint aste_w_bi aste_w_joint aste_vbeh_w
	foreach var in `astelist' {
		cap confirm variable `var'
		if !_rc {
			sum `var' if control==1
			replace `var'=(`var'-`r(mean)')/`r(sd)'		
		}
		sum E`var' if control==1
		replace E`var'=(E`var'-`r(mean)')/`r(sd)'		
	}	
	
}	
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*								Lee-Bounds 										*	
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *	
{
***** Iterate over the different pairwise groups
decode treat, gen(treatstring)

/*
	1. WCommHN Vs WHN 
	2. WCommHN Vs Control

*/

global pairgroup inlist(treat,2,1) inlist(treat,2,3)

foreach pair in $pairgroup {
	
preserve	
	* Keep pair-wise analysis groups
	keep if `pair'
	
	* Generate treatment variable
	gen treatvar=(treat==2)	
		local treatgroup "WCommHN"
		
		if "`pair'" =="inlist(treat,2,3)" {
			local saveas whn
			local controlgroupwhn "WHN"
			
		}
		if "`pair'" =="inlist(treat,2,1)" {
			local saveas cont
			local controlgroupcont "Control"
			
		}		
	* Dependent variables 
	local vars Ew_rel_improve_aste Easte_w_bi Easte_w_joint Easte_vbeh_w	

	gen B_treat_l=treatvar
	gen B_treat_u=treatvar
	
	lab var treatvar "`treatgroup'"
	lab var B_treat_l "`treatgroup' (Lower bound)"
	lab var B_treat_u "`treatgroup' (Upper bound)"

	local tablerow treatvar B_treat_l B_treat_u

	local varlab1: var lab treatvar
	local varlab2: var lab B_treat_l
	local varlab3: var lab B_treat_u

	summ treatvar if treatvar==1 
	local t_N = r(N) //count how many treatment observations we have
	summ treatvar if treatvar==0 
	local c_N = r(N) //count how many control observations we have

	summ treatvar 
	local all_N= r(N)
	
	
		di _n "*********************** Endline 3  ************************" _n
		di _n "Total : `all_N'"  _n			 
		di _n "Total control : `c_N'"  _n	
		di _n "Total treatment : `t_N'"  _n	
	
	gen miss = 0		
	local i=0
	set seed 412024
	gen x=runiform() // to break Lee bounds ties

	eststo clear
	foreach v in `vars' { // the local vars has the outcome variables of interest

		gen TLO_`v' = 0		// obsns to trim for lower bound
		gen TUP_`v' = 0		// obsns to trim for upper bound
		gen TABS_`v' = 0	// obsns to trim for lower bound in absolute value terms

		* final total obs by treatment and control
		local ft_N = `t_N'		
		local fc_N = `c_N'		

		
		*Leebounds
		
		* Confirm if there is a variable in baseline to control for
		local ldv`v'= substr("`v'",2,.)		
		
		
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' treatvar district1 district2 district3 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  treatvar district1 district2 district3 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}

	
		local posneg = sign(_b[treatvar])	// Is treatment effect with untrimmed sample positive or negative?
		replace miss = (`v'== .)		// This is so when sorting data below and using _n, don't have to worry if Stata puts missing values first or last
		
		summ `v' if treatvar==1 
		local t_n = r(N)
		local t_rate = `t_n'/`ft_N'		// retention rate for treatment group
		
		summ `v' if treatvar==0 
		local c_n = r(N)
		local c_rate = `c_n'/`fc_N'		// retention rate for control group

		
		local trim_rate = abs(`c_rate' - `t_rate')	// % of obsns to trim
		

		
		* Missing rate 
		local t_miss =`ft_N' - `t_n'
		local c_miss =`fc_N' - `c_n'
		
		local t_miss_rate=`t_miss'/`ft_N'
		local c_miss_rate=`c_miss'/`fc_N'
		local m_t_`v': di %5.3fc `t_miss_rate'
		local m_c_`v': di %5.3fc `c_miss_rate'
		di _n " " _n		
		di _n "Outcome : `v'" _n	
		di _n "		Non-Missing control : `c_n' & Non-Missing  treatment : `t_n'" _n		
		di _n "	            Treatment missing rate:  `t_miss_rate'" _n	
		di _n "             Control missing rate:  `c_miss_rate'" _n			
		di _n "             Trim rate:  `trim_rate'" _n	
	
		if `c_rate' > `t_rate' {  // trim from control group
			local trim_n = round(`trim_rate'* `fc_N')	// number of obsns to trim

			*cap confirm variable `v'			
			 gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat `v' x /*-B_S`v'*/
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 	// trim low values from control group to get lower bound
			
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x
			
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 
		}

		if `c_rate' < `t_rate' {  // trim from treat group
			local trim_n = round(`trim_rate'* `ft_N')	// number of obsns to trim
			di `trim_n'
			*cap confirm variable B_S`v'			
			gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat E_S`v' -B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0	*/ // trim low values from treat group to get upper bound
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x 
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0*/
		}		

		* Lower bound in absolute value terms depends on whether coefficient is positive or negative (unlikely to be exactly 0, but if so, full sample gives lower abs value bound)
		if `posneg'==1 {
			replace TABS_`v' = TLO_`v' 	// if treatment effect is positive, lower bound in absolute value terms is actual lower bound

		}
		if `posneg'==-1 {
			replace TABS_`v' = TUP_`v' // if treatment effect is negative, lower bound in absolute value terms is actual upper bound
		}		

		di _n "*****   Full sample   *****" _n		
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' treatvar district1 district2 district3 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  treatvar district1 district2 district3 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		
		local cluster_`v': di %7.0fc `e(N_clust)'
		local obs_`v': di %7.0fc `e(N)'
		local treat_`v': di %7.3fc _b[treatvar]
		local se_`v': di %7.3fc _se[treatvar]		
		local t_`v' = _b[treatvar]/_se[treatvar]
		scalar p_`v' = 2*ttail(e(df_r),abs(`t_`v''))

		dis "cluster_`v' : `cluster_`v''"
		dis "obs_`v' : `obs_`v''"
		dis "treat_`v' : `treat_`v''"
		dis "se_`v' : `se_`v''"
		dis "t_`v' : `t_`v''"
		dis "p`v' :"
		dis p_`v'
		
		
		
		di _n "*****   Lower bound   *****" _n
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' B_treat_l district1 district2 district3 if TLO_`v'==0, 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  B_treat_l district1 district2 district3 if TLO_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		
		local obs1_`v' : di %7.0fc `e(N)'
		local treat_l_`v': di %7.3fc _b[B_treat_l]
		local se_l_`v': di %7.3fc _se[B_treat_l]
		local t_l_`v' = _b[B_treat_l]/_se[B_treat_l]
		scalar p_l_`v' = 2*ttail(e(df_r),abs(`t_l_`v''))
		dis "obs_l_`v' : `obs_l_`v''"
		dis "treat_l_`v' : `treat_l_`v''"
		dis "se_l_`v' : `se_l_`v''"
		dis "t_l_`v' : `t_l_`v''"
		dis "p_l`v' :"
		dis p_l_`v'

		
		
		di _n "*****   Upper bound   *****" _n		
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' B_treat_u district1 district2 district3 if TUP_`v'==0, 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  B_treat_u district1 district2 district3 if TUP_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		
		
		local treat_u_`v': di %7.3fc _b[B_treat_u]
		local se_u_`v': di %7.3fc _se[B_treat_u]
		local t_u_`v' = _b[B_treat_u]/ _se[B_treat_u]
		scalar p_u_`v' = 2*ttail(e(df_r),abs(`t_u_`v''))
		dis p_u_`v'
		dis "obs_u_`v' : `obs_u_`v''"
		dis "treat_u_`v' : `treat_u_`v''"
		dis "se_u_`v' : `se_u_`v''"
		dis "t_u_`v' : `t_u_`v''"
		dis "p_u`v' :"
		dis p_u_`v'		
	

		di _n "*****   Bound on magnitude   *****" _n
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' treatvar district1 district2 district3 if TABS_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  treatvar district1 district2 district3 if TABS_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}	
	
		
		
		if p_`v'< 0.01 {
			local treat_`v' `treat_`v''\sym{***}
		}
		else if 0.01 <= p_`v' & p_`v' < 0.05 {
			local treat_`v' `treat_`v''\sym{**}
		}
		else if 0.05 <= p_`v' & p_`v' < 0.1 {
			local treat_`v' `treat_`v''\sym{*}
		}
		else if p_`v'> 0.1 {
			local treat_`v' `treat_`v''
		}
		
		if p_l_`v'< 0.01 {
			local treat_l_`v' `treat_l_`v''\sym{***}
		}
		else if 0.01<= p_l_`v' & p_l_`v' < 0.05 {
			local treat_l_`v' `treat_l_`v''\sym{**}
		}
		else if 0.05<= p_l_`v' & p_l_`v' < 0.1 {
			local treat_l_`v' `treat_l_`v''\sym{*}
		}
		else if p_l_`v'> 0.1 {
			local treat_l_`v' `treat_l_`v''
		}
		
		if p_u_`v'< 0.01 {
			local treat_u_`v' `treat_u_`v''\sym{***}
		}
		else if 0.01<= p_u_`v' & p_u_`v' < 0.05 {
			local treat_u_`v' `treat_u_`v''\sym{**}
		}
		else if 0.05<= p_u_`v' & p_u_`v' < 0.1 {
			local treat_u_`v' `treat_u_`v''\sym{*}
		}
		else if p_u_`v'> 0.1 {
			local treat_u_`v' `treat_u_`v''
		}
	}

	local se
	foreach var in `vars'  {
		local se `se' se_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_l_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_u_`var'
	}
	
	foreach x in `se' {
		local `x'=trim(string(``x'',"%7.3f"))
	}


	* header and no. of columns
	eststo clear
	local header
	local n_col =0
	foreach var in `vars'   {

		local varlab: variable label `var'
		local header "`header' & `varlab'" // column headers with variables labels 
		
		local ++n_col // number of columns		
		
	}


	local writetreat`saveas' `varlab1'
	local writetreat_l`saveas' `varlab2'
 	local writetreat_u`saveas' `varlab3'
	local writese`saveas'
	local writese_l`saveas'
	local writese_u`saveas' 
	local writeobs`saveas'
	local writeobs1`saveas'
	local writemis_c`saveas'
	
	
	
	foreach var in `vars'  {
		local treat_`var' `treat_`var''
		local se_`var' `se_`var''
		local treat_l_`var' `treat_l_`var''
		local se_l_`var' `se_l_`var''
		local treat_u_`var' `treat_u_`var''
		local se_u_`var' `se_u_`var''
		local obs_`var' `obs_`var''
		local obs1_`var' `obs1_`var''
		local miss_c_`var' `m_c_`var''
		
	local writemis_c`saveas' `writemis_c`saveas'' & `miss_c_`var''		
	local writetreat`saveas' `writetreat`saveas'' & `treat_`var''
	local writetreat_l`saveas' `writetreat_l`saveas'' & `treat_l_`var''
	local writetreat_u`saveas' `writetreat_u`saveas'' & `treat_u_`var''

	local writese`saveas' `writese`saveas'' & [`se_`var'']
	local writese_l`saveas' `writese_l`saveas'' & [`se_l_`var'']
	local writese_u`saveas' `writese_u`saveas'' & [`se_u_`var'']
	
	local writeobs`saveas' `writeobs`saveas'' & `obs_`var''
	local writeobs1`saveas' `writeobs1`saveas'' & `obs1_`var''


	/*
	dis "miss_x_`var' : `miss_x_`var''"
	dis "miss_c_`var' : `miss_c_`var''"
	
	dis " writetreat : `writetreat`saveas''"	
	dis " writetreat_l : `writetreat_l`saveas''"	
	dis " writetreat_u : `writetreat_u`saveas''"	
	dis " writese : `writese`saveas''"	
	dis " writese_l : `writese_l`saveas''"	
	dis " writese_u : `writese_u`saveas''"	
	dis " writeobs : `writeobs`saveas''"	
	dis " writeobs1 : `writeobs1`saveas''"	
	dis " writemis_x : `writemis_x'`saveas'"	
		*/	
	dis " writemis_c`saveas' : `writemis_c`saveas''"	

	}

* Missing rate for treatment	
local writemis_treat`saveas'
foreach var in `vars'  {
	local a_`var' `m_t_`var''
	local mrate_treat`saveas' `mrate_treat`saveas'' & `m_t_`var''		
	dis "`mrate_treat`saveas''"
	}
restore
		}

	
* Layout options
	#d ;
	local frame "{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\renewcommand{\arraystretch}{rowspace}  
		\begin{tabular}{{>{\hangindent=1em}p{first}}*{colno}{>{\centering\arraybackslash}m{colspace}}}
		\toprule";
	#d cr	

	local frame0 = subinstr("`frame'", "first", "5.5cm", .) // first column width
	local frame1 = subinstr("`frame0'", "colspace", "2.4cm", .) // column spacing 
	local frame2 = subinstr("`frame1'", "rowspace", "1", .) // row spacing
	local prehead = subinstr("`frame2'", "colno", "4", .)	// number of columns		
	
		*** combined table
		cap file close regtab
		file open regtab using "$tables/table_A3a.tex", write replace
		
		
		file write regtab "`prehead' \\" _n      
		file write regtab "& Relationship improved ASTE & Wife part of household decisions ASTE & Couple makes decisions together ASTE & Husband is less violent ASTE \\" _n
		file write regtab "  & (1) & (2) & (3) & (4) \\    " _n    
		file write regtab "\midrule" _n 
		file write regtab "& \multicolumn{4}{c}{\textbf{WCommHN vs. Control}} \\" _n
		
		
		* Control
		file write regtab "\cmidrule(lr){2-5} `writetreat_lcont' \\  " _n	
		file write regtab  " `writese_lcont' \\  " _n
		

		file write regtab "`writetreat_ucont' \\  " _n	
		file write regtab  "`writese_ucont' \\  " _n		
		file write regtab "\midrule" _n 
		
		file write regtab "`treatgroup' missing rate `mrate_treatcont' \\ " _n	
		file write regtab "`controlgroupcont' missing rate  `writemis_ccont' \\ " _n	
		
		
		* WHN
		file write regtab "\midrule" _n 
		file write regtab "& \multicolumn{4}{c}{\textbf{WCommHN vs. WHN}} \\" _n
		
		file write regtab "\cmidrule(lr){2-5} `writetreat_lwhn' \\  " _n	
		file write regtab  " `writese_lwhn' \\  " _n
		

		file write regtab "`writetreat_uwhn' \\  " _n	
		file write regtab  "`writese_uwhn' \\  " _n		

		file write regtab "\midrule" _n 
		
		file write regtab "`treatgroup' missing rate  `mrate_treatwhn' \\ " _n	
		file write regtab "`controlgroupwhn' missing rate  `writemis_cwhn' \\ " _n			
		
	
	
	
	
		file write regtab "\bottomrule" _n           // table footer
		file write regtab "\end{tabular} }" _n 
		file close regtab

}

}
	
	
*===============================================================================*			
* Table A.3b: Program impacts on frequency of spousal discussion about targeted health 
*             topics and women's and men's health knowledge: Lee bounds.
*===============================================================================*		

	if `table_a3b' == 1 {	

	eststo clear	
	estimates clear
	{
	use "$analysis/womens_mens_mcm.dta", clear
	
	tab districtid, gen(district)
	drop district4	
		
	recode m_fp_talk (98=.)
	
	foreach y in w_fp_talk m_fp_talk Ew_fp_talk Em_fp_talk {
		gen `y'_yno = 0 if `y' == 1
		replace `y'_yno = 1 if inlist(`y',2,3)
	}
	gen Ew_talk_hiv = (Ew_talked_hiv == 1) if !mi(Ew_talked_hiv)
	
	
	local varlist w_husb_sugg_food_vo w_discuss_spouse_vo w_husb_sugg_hc_vo
	
	foreach var in `varlist' {
		sum E`var' if control == 1
		gen EE`var'=(E`var'-`r(mean)')/`r(sd)'
	}
	
	* ASTE, normalized so that SD=1
	
	cap drop EWhusb_HnN_index
	egen EWhusb_HnN_index=rowmean(EEw_husb_sugg_food_vo EEw_discuss_spouse_vo EEw_husb_sugg_hc_vo)	
	sum EWhusb_HnN_index if control==1
	replace EWhusb_HnN_index=(EWhusb_HnN_index-`r(mean)')/`r(sd)'	
	
	gen Ew_plan_hhexpend6 = Ew_plan_hhexpend12
		
	local varlist w_fp_talk_yno w_talk_hiv w_plan_hhexpend6
	
	foreach var in `varlist' {
	cap confirm variable `var'
		if !_rc {
			sum `var' if control == 1
			gen B`var'=(`var'-`r(mean)')/`r(sd)'
		}
		sum E`var' if control == 1
		gen EE`var'=(E`var'-`r(mean)')/`r(sd)'
	}
	
	egen Ew_marcomm_aste = rowmean(EEw_fp_talk_yno EEw_talk_hiv EEw_husb_sugg_food_vo EEw_discuss_spouse_vo EEw_husb_sugg_hc_vo EEw_plan_hhexpend6)
	egen w_marcomm_aste = rowmean(Bw_fp_talk_yno Bw_plan_hhexpend6)
	
	foreach var in w_marcomm_aste Ew_marcomm_aste {
		sum `var' if control==1
		replace `var'=(`var'-`r(mean)')/`r(sd)'				
	}	
	decode treat, gen(treatstring)
	tempfile table2dataset
	save `table2dataset', replace
	
	* Expand sample if column 6 and 7
			set seed 412024
			expand=2
			bys id: gen n=_n
			lab define GENDER 1 "Woman" 2 "Man", modify
			lab values n GENDER
			
			#delimit ;
			local health_knowledge_vars
				cstrum_impt_why_bi
				ageliquid_6
				agefood_6
				grow_lackdiet_vm
				bfeed24
				timedeworm_5
				child_worms_bi
				child_vomit_bi
				boys_eatmore_bi
				safe_primhc_bi
				menprot_bi
				anem_foods_bi 
				boil_1min_bi
				condom_times_bi
				hygint_bi
				food_plate_bi ;
			#delimit cr
			
			foreach var in `health_knowledge_vars' {
				cap confirm variable m_`var'     // if the variable exists for men, it also exists for women 
				if !_rc {   
					gen B`var'=w_`var' if n==1
					replace B`var'=m_`var' if n==2
				}	
				cap confirm variable Em_`var'   // if the variable exists for men, it also exists for women 
				if !_rc {            
					gen E`var'=Ew_`var' if n==1
					replace E`var'=Em_`var' if n==2
				}	
				* standardize with respect to control group
				cap confirm variable B`var'
				if !_rc {
					sum B`var' if control == 1 // stats for entire sample = men + women 
					gen BL_`var'=(B`var'-`r(mean)')/`r(sd)' // baseline health knowledge
				}
				cap confirm variable E`var'
				if !_rc {
					sum E`var' if control == 1 // stats for entire sample = men + women 
					gen EL_`var'=(E`var'-`r(mean)')/`r(sd)' // endline health knowledge
				}
			}
			
			//// Endline index

			cap drop *Hknowl_index 
				
			#delimit ;
			egen EL_Hknowl_index = rowmean(	
				EL_cstrum_impt_why_bi
				EL_ageliquid_6
				EL_agefood_6
				EL_grow_lackdiet_vm
				EL_bfeed24
				EL_timedeworm_5
				EL_child_worms_bi
				EL_child_vomit_bi
				EL_boys_eatmore_bi
				EL_safe_primhc_bi
				EL_menprot_bi
				EL_anem_foods_bi 
				EL_boil_1min_bi
				EL_condom_times_bi
				EL_hygint_bi
				EL_food_plate_bi) 	
			;
			#delimit cr
					
			//// Baseline index
			
			#delimit ;
			egen BL_Hknowl_index = rowmean(
				BL_ageliquid_6
				BL_agefood_6
				BL_grow_lackdiet_vm
				BL_bfeed24
				BL_timedeworm_5
				BL_menprot_bi 
				BL_boil_1min_bi
				BL_hygint_bi)
				;
			#delimit cr
			
			sum BL_Hknowl_index if n==1 // women's baseline health knowledge
			sum BL_Hknowl_index if n==2 // men's baseline health knowledge

			* Normalize ASTEs so that SD=1	
			
			foreach var in BL_Hknowl_index EL_Hknowl_index {
				sum `var' if control==1
				replace `var'=(`var'-`r(mean)')/`r(sd)'				
				sum `var' if control==1	// SD=1
			}
			
			sum BL_Hknowl_index if n==1 // women's baseline health knowledge
			sum BL_Hknowl_index if n==2 // men's baseline health knowledge
			
	tempfile table2datasetexpanded
	save `table2datasetexpanded', replace		
	}	
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*								Lee-Bounds 										*	
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *	

* Column 6
use `table2datasetexpanded', clear

keep if n==1

global pairgroup inlist(treat,2,1) inlist(treat,2,3)

foreach pair in $pairgroup {
	
preserve	
	* Keep pair-wise analysis groups
	keep if `pair'
	
	* Generate treatment variable
	gen treatvar=(treat==2)	
		local treatgroup "WCommHN"
		
		if "`pair'" =="inlist(treat,2,3)" {
			local saveas whn
			local controlgroupwhn "WHN"
			
		}
		if "`pair'" =="inlist(treat,2,1)" {
			local saveas cont
			local controlgroupcont "Control"
			
		}				
	* Dependent variables
	local vars EL_Hknowl_index 

	gen B_treat_l=treatvar
	gen B_treat_u=treatvar
	
	lab var treatvar "`treatgroup'"
	lab var B_treat_l "`treatgroup' (Lower bound)"
	lab var B_treat_u "`treatgroup' (Upper bound)"

	local tablerow treatvar B_treat_l B_treat_u

	local varlab1: var lab treatvar
	local varlab2: var lab B_treat_l
	local varlab3: var lab B_treat_u

	summ treatvar if treatvar==1 
	local t_N = r(N) //count how many treatment observations we have
	summ treatvar if treatvar==0 
	local c_N = r(N) //count how many control observations we have

	summ treatvar 
	local all_N= r(N)
	
	
		di _n "*********************** Endline 3  ************************" _n
		di _n "Total : `all_N'"  _n			 
		di _n "Total control : `c_N'"  _n	
		di _n "Total treatment : `t_N'"  _n	
	
	gen miss = 0		
	local i=0
	set seed 412024
	gen x=runiform() // to break Lee bounds ties

	eststo clear
	foreach v in `vars' { // the local vars has the outcome variables of interest

		gen TLO_`v' = 0		// obsns to trim for lower bound
		gen TUP_`v' = 0		// obsns to trim for upper bound
		gen TABS_`v' = 0	// obsns to trim for lower bound in absolute value terms

		* final total obs by treatment and control
		local ft_N = `t_N'		
		local fc_N = `c_N'		

		

		
		
		*Leebounds
		areg `v' BL_Hknowl_index treatvar district1 district2 district3 if n==1, a(stratum) cluster(villageid)
		local posneg = sign(_b[treatvar])	
		replace miss = (`v'== .)		// This is so when sorting data below and using _n, don't have to worry if Stata puts missing values first or last
		
		summ `v' if treatvar==1 
		local t_n = r(N)
		local t_rate = `t_n'/`ft_N'		// retention rate for treatment group
		
		summ `v' if treatvar==0 
		local c_n = r(N)
		local c_rate = `c_n'/`fc_N'		// retention rate for control group

		
		local trim_rate = abs(`c_rate' - `t_rate')	// % of obsns to trim
		

		
		* Missing rate 
		local t_miss =`ft_N' - `t_n'
		local c_miss =`fc_N' - `c_n'
		
		local t_miss_rate=`t_miss'/`ft_N'
		local c_miss_rate=`c_miss'/`fc_N'
		local missrate_t_`v': di %7.3fc  `t_miss_rate'
		local missrate_c_`v': di %7.3fc `c_miss_rate'

		di _n " " _n		
		di _n "Outcome : `v'" _n	
		di _n "		Non-Missing control : `c_n' & Non-Missing  treatment : `t_n'" _n		
		di _n "	            Treatment missing rate:  `t_miss_rate'" _n	
		di _n "             Control missing rate:  `c_miss_rate'" _n			
		di _n "             Trim rate:  `trim_rate'" _n	
		
		
	
		if `c_rate' > `t_rate' {  // trim from control group
			local trim_n = round(`trim_rate'* `fc_N')	// number of obsns to trim

			*cap confirm variable `v'			
			 gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat `v' x /*-B_S`v'*/
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 	// trim low values from control group to get lower bound
			
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x
			
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 
		}

		if `c_rate' < `t_rate' {  // trim from treat group
			local trim_n = round(`trim_rate'* `ft_N')	// number of obsns to trim
			di `trim_n'
			*cap confirm variable B_S`v'			
			gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat E_S`v' -B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0	*/ // trim low values from treat group to get upper bound
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x 
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0*/
		}		

		* Lower bound in absolute value terms depends on whether coefficient is positive or negative (unlikely to be exactly 0, but if so, full sample gives lower abs value bound)
		if `posneg'==1 {
			replace TABS_`v' = TLO_`v' 	// if treatment effect is positive, lower bound in absolute value terms is actual lower bound

		}
		if `posneg'==-1 {
			replace TABS_`v' = TUP_`v' // if treatment effect is negative, lower bound in absolute value terms is actual upper bound
		}		

		di _n "*****   Full sample   *****" _n		
		
	
		areg `v' BL_Hknowl_index treatvar district1 district2 district3 if n==1, a(stratum) cluster(villageid)
	
	
		
		local cluster_`v': di %7.0fc `e(N_clust)'
		local obs_`v': di %7.0fc `e(N)'
		local treat_`v': di %7.3fc _b[treatvar]
		local se_`v': di %7.3fc _se[treatvar]		
		local t_`v' = _b[treatvar]/_se[treatvar]
		scalar p_`v' = 2*ttail(e(df_r),abs(`t_`v''))

		dis "cluster_`v' : `cluster_`v''"
		dis "obs_`v' : `obs_`v''"
		dis "treat_`v' : `treat_`v''"
		dis "se_`v' : `se_`v''"
		dis "t_`v' : `t_`v''"
		dis "p`v' :"
		dis p_`v'
		
		
		
		di _n "*****   Lower bound   *****" _n
		
		
		areg EL_Hknowl_index BL_Hknowl_index B_treat_l district1 district2 district3 if n==1 & TLO_`v'==0, a(stratum) cluster(villageid)
				
			
		local obs1_`v' : di %7.0fc `e(N)'
		local treat_l_`v': di %7.3fc _b[B_treat_l]
		local se_l_`v': di %7.3fc _se[B_treat_l]
		local t_l_`v' = _b[B_treat_l]/_se[B_treat_l]
		scalar p_l_`v' = 2*ttail(e(df_r),abs(`t_l_`v''))
		dis "obs_l_`v' : `obs_l_`v''"
		dis "treat_l_`v' : `treat_l_`v''"
		dis "se_l_`v' : `se_l_`v''"
		dis "t_l_`v' : `t_l_`v''"
		dis "p_l`v' :"
		dis p_l_`v'

		
		
		di _n "*****   Upper bound   *****" _n		
		
			areg `v' BL_Hknowl_index B_treat_u district1 district2 district3 if n==1 & TUP_`v'==0, a(stratum) cluster(villageid)
						
		
		local treat_u_`v': di %7.3fc _b[B_treat_u]
		local se_u_`v': di %7.3fc _se[B_treat_u]
		local t_u_`v' = _b[B_treat_u]/ _se[B_treat_u]
		scalar p_u_`v' = 2*ttail(e(df_r),abs(`t_u_`v''))
		dis p_u_`v'
		dis "obs_u_`v' : `obs_u_`v''"
		dis "treat_u_`v' : `treat_u_`v''"
		dis "se_u_`v' : `se_u_`v''"
		dis "t_u_`v' : `t_u_`v''"
		dis "p_u`v' :"
		dis p_u_`v'		
	

		di _n "*****   Bound on magnitude   *****" _n
		
	
		areg `v' BL_Hknowl_index treatvar district1 district2 district3 if n==1 & TABS_`v'==0, a(stratum) cluster(villageid)
						
		
		if p_`v'< 0.01 {
			local treat_`v' `treat_`v''\sym{***}
		}
		else if 0.01 <= p_`v' & p_`v' < 0.05 {
			local treat_`v' `treat_`v''\sym{**}
		}
		else if 0.05 <= p_`v' & p_`v' < 0.1 {
			local treat_`v' `treat_`v''\sym{*}
		}
		else if p_`v'> 0.1 {
			local treat_`v' `treat_`v''
		}
		
		if p_l_`v'< 0.01 {
			local treat_l_`v' `treat_l_`v''\sym{***}
		}
		else if 0.01<= p_l_`v' & p_l_`v' < 0.05 {
			local treat_l_`v' `treat_l_`v''\sym{**}
		}
		else if 0.05<= p_l_`v' & p_l_`v' < 0.1 {
			local treat_l_`v' `treat_l_`v''\sym{*}
		}
		else if p_l_`v'> 0.1 {
			local treat_l_`v' `treat_l_`v''
		}
		
		if p_u_`v'< 0.01 {
			local treat_u_`v' `treat_u_`v''\sym{***}
		}
		else if 0.01<= p_u_`v' & p_u_`v' < 0.05 {
			local treat_u_`v' `treat_u_`v''\sym{**}
		}
		else if 0.05<= p_u_`v' & p_u_`v' < 0.1 {
			local treat_u_`v' `treat_u_`v''\sym{*}
		}
		else if p_u_`v'> 0.1 {
			local treat_u_`v' `treat_u_`v''
		}
	}

	local se
	foreach var in `vars'  {
		local se `se' se_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_l_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_u_`var'
	}
	
	foreach x in `se' {
		local `x'=trim(string(``x'',"%7.3f"))
	}





	local writetreatcol6`saveas' 
	local writetreat_lcol6`saveas'
 	local writetreat_ucol6`saveas' 
	local writesecol6`saveas'
	local writese_lcol6`saveas'
	local writese_ucol6`saveas' 
	local writeobscol6`saveas'
	local writeobs1col6`saveas'
	local writemistcol6`saveas'
	local writemisccol6`saveas'
	
	


	foreach var in `vars'  {
		local treat_`var' `treat_`var''
		local se_`var' `se_`var''
		local treat_l_`var' `treat_l_`var''
		local se_l_`var' `se_l_`var''
		local treat_u_`var' `treat_u_`var''
		local se_u_`var' `se_u_`var''
		local obs_`var' `obs_`var''
		local obs1_`var' `obs1_`var''
		local miss_t_`var' `missrate_t_`var''
		local miss_c_`var' `missrate_c_`var''
		
		
		
	local writetreatcol6`saveas' `writetreatcol6`saveas'' & `treat_`var''
	local writetreat_lcol6`saveas' `writetreat_lcol6`saveas'' & `treat_l_`var''
	local writetreat_ucol6`saveas' `writetreat_ucol6`saveas'' & `treat_u_`var''

	local writesecol6`saveas' `writesecol6`saveas'' & [`se_`var'']
	local writese_lcol6`saveas' `writese_lcol6`saveas'' & [`se_l_`var'']
	local writese_ucol6`saveas' `writese_ucol6`saveas'' & [`se_u_`var'']
	
	local writeobscol6`saveas' `writeobscol6`saveas'' & `obs_`var''
	local writeobs1col6`saveas' `writeobs1col6`saveas'' & `obs1_`var''
	local writemistcol6`saveas' `writemistcol6`saveas'' & `miss_t_`var''
	local writemisccol6`saveas' `writemisccol6`saveas'' & `miss_c_`var''


	}
restore	
	}


* Column 7
use `table2datasetexpanded', clear

keep if n==2

global pairgroup inlist(treat,2,1) inlist(treat,2,3)

foreach pair in $pairgroup {
	
preserve	
	* Keep pair-wise analysis groups
	keep if `pair'
	
	* Generate treatment variable
	gen treatvar=(treat==2)	
		local treatgroup "WCommHN"
		if "`pair'" =="inlist(treat,2,3)" {
			local saveas whn
			local controlgroupwhn "WHN"
			
		}
		if "`pair'" =="inlist(treat,2,1)" {
			local saveas cont
			local controlgroupcont "Control"
			
		}		
	* Dependent variables 
	local vars EL_Hknowl_index
	gen B_treat_l=treatvar
	gen B_treat_u=treatvar
	
	lab var treatvar "`treatgroup'"
	lab var B_treat_l "`treatgroup' (Lower bound)"
	lab var B_treat_u "`treatgroup' (Upper bound)"

	local tablerow treatvar B_treat_l B_treat_u

	local varlab1: var lab treatvar
	local varlab2: var lab B_treat_l
	local varlab3: var lab B_treat_u

	summ treatvar if treatvar==1 
	local t_N = r(N) //count how many treatment observations we have
	summ treatvar if treatvar==0 
	local c_N = r(N) //count how many control observations we have

	summ treatvar 
	local all_N= r(N)
	
	
		di _n "*********************** Endline 3  ************************" _n
		di _n "Total : `all_N'"  _n			 
		di _n "Total control : `c_N'"  _n	
		di _n "Total treatment : `t_N'"  _n	
	
	gen miss = 0		
	local i=0
	set seed 412024
	gen x=runiform() // to break Lee bounds ties

	eststo clear
	foreach v in `vars' { // the local vars has the outcome variables of interest

		gen TLO_`v' = 0		// obsns to trim for lower bound
		gen TUP_`v' = 0		// obsns to trim for upper bound
		gen TABS_`v' = 0	// obsns to trim for lower bound in absolute value terms

		* final total obs by treatment and control
		local ft_N = `t_N'		
		local fc_N = `c_N'		

		

		
		
		*Leebounds
		areg `v' BL_Hknowl_index treatvar district1 district2 district3 if n==2, a(stratum) cluster(villageid)
		local posneg = sign(_b[treatvar])	
		replace miss = (`v'== .)		// This is so when sorting data below and using _n, don't have to worry if Stata puts missing values first or last
		
		summ `v' if treatvar==1 
		local t_n = r(N)
		local t_rate = `t_n'/`ft_N'		// retention rate for treatment group
		
		summ `v' if treatvar==0 
		local c_n = r(N)
		local c_rate = `c_n'/`fc_N'		// retention rate for control group

		
		local trim_rate = abs(`c_rate' - `t_rate')	// % of obsns to trim
		

		
		* Missing rate 
		local t_miss =`ft_N' - `t_n'
		local c_miss =`fc_N' - `c_n'
		
		local t_miss_rate=`t_miss'/`ft_N'
		local c_miss_rate=`c_miss'/`fc_N'
		local missrate_t_`v': di %7.3fc  `t_miss_rate'
		local missrate_c_`v': di %7.3fc `c_miss_rate'

		di _n " " _n		
		di _n "Outcome : `v'" _n	
		di _n "		Non-Missing control : `c_n' & Non-Missing  treatment : `t_n'" _n		
		di _n "	            Treatment missing rate:  `t_miss_rate'" _n	
		di _n "             Control missing rate:  `c_miss_rate'" _n			
		di _n "             Trim rate:  `trim_rate'" _n	
		
		
	
		if `c_rate' > `t_rate' {  // trim from control group
			local trim_n = round(`trim_rate'* `fc_N')	// number of obsns to trim

			*cap confirm variable `v'			
			 gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat `v' x /*-B_S`v'*/
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 	// trim low values from control group to get lower bound
			
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x
			
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 
		}

		if `c_rate' < `t_rate' {  // trim from treat group
			local trim_n = round(`trim_rate'* `ft_N')	// number of obsns to trim
			di `trim_n'
			*cap confirm variable B_S`v'			
			gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat E_S`v' -B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0	*/ // trim low values from treat group to get upper bound
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x 
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0*/
		}		

		* Lower bound in absolute value terms depends on whether coefficient is positive or negative (unlikely to be exactly 0, but if so, full sample gives lower abs value bound)
		if `posneg'==1 {
			replace TABS_`v' = TLO_`v' 	// if treatment effect is positive, lower bound in absolute value terms is actual lower bound

		}
		if `posneg'==-1 {
			replace TABS_`v' = TUP_`v' // if treatment effect is negative, lower bound in absolute value terms is actual upper bound
		}		

		di _n "*****   Full sample   *****" _n		
		
	
		areg `v' BL_Hknowl_index treatvar district1 district2 district3 if n==2, a(stratum) cluster(villageid)
	
	
		
		local cluster_`v': di %7.0fc `e(N_clust)'
		local obs_`v': di %7.0fc `e(N)'
		local treat_`v': di %7.3fc _b[treatvar]
		local se_`v': di %7.3fc _se[treatvar]		
		local t_`v' = _b[treatvar]/_se[treatvar]
		scalar p_`v' = 2*ttail(e(df_r),abs(`t_`v''))

		dis "cluster_`v' : `cluster_`v''"
		dis "obs_`v' : `obs_`v''"
		dis "treat_`v' : `treat_`v''"
		dis "se_`v' : `se_`v''"
		dis "t_`v' : `t_`v''"
		dis "p`v' :"
		dis p_`v'
		
		
		
		di _n "*****   Lower bound   *****" _n
		
		
		areg `v' BL_Hknowl_index B_treat_l district1 district2 district3 if n==2 & TLO_`v'==0, a(stratum) cluster(villageid)
				
			
		local obs1_`v' : di %7.0fc `e(N)'
		local treat_l_`v': di %7.3fc _b[B_treat_l]
		local se_l_`v': di %7.3fc _se[B_treat_l]
		local t_l_`v' = _b[B_treat_l]/_se[B_treat_l]
		scalar p_l_`v' = 2*ttail(e(df_r),abs(`t_l_`v''))
		dis "obs_l_`v' : `obs_l_`v''"
		dis "treat_l_`v' : `treat_l_`v''"
		dis "se_l_`v' : `se_l_`v''"
		dis "t_l_`v' : `t_l_`v''"
		dis "p_l`v' :"
		dis p_l_`v'

		
		
		di _n "*****   Upper bound   *****" _n		
		
		areg `v' BL_Hknowl_index B_treat_u district1 district2 district3 if n==2 & TUP_`v'==0, a(stratum) cluster(villageid)
						
		
		local treat_u_`v': di %7.3fc _b[B_treat_u]
		local se_u_`v': di %7.3fc _se[B_treat_u]
		local t_u_`v' = _b[B_treat_u]/ _se[B_treat_u]
		scalar p_u_`v' = 2*ttail(e(df_r),abs(`t_u_`v''))
		dis p_u_`v'
		dis "obs_u_`v' : `obs_u_`v''"
		dis "treat_u_`v' : `treat_u_`v''"
		dis "se_u_`v' : `se_u_`v''"
		dis "t_u_`v' : `t_u_`v''"
		dis "p_u`v' :"
		dis p_u_`v'		
	

		di _n "*****   Bound on magnitude   *****" _n
		
	
		areg `v' BL_Hknowl_index treatvar district1 district2 district3 if n==2 & TABS_`v'==0, a(stratum) cluster(villageid)
						
		
		if p_`v'< 0.01 {
			local treat_`v' `treat_`v''\sym{***}
		}
		else if 0.01 <= p_`v' & p_`v' < 0.05 {
			local treat_`v' `treat_`v''\sym{**}
		}
		else if 0.05 <= p_`v' & p_`v' < 0.1 {
			local treat_`v' `treat_`v''\sym{*}
		}
		else if p_`v'> 0.1 {
			local treat_`v' `treat_`v''
		}
		
		if p_l_`v'< 0.01 {
			local treat_l_`v' `treat_l_`v''\sym{***}
		}
		else if 0.01<= p_l_`v' & p_l_`v' < 0.05 {
			local treat_l_`v' `treat_l_`v''\sym{**}
		}
		else if 0.05<= p_l_`v' & p_l_`v' < 0.1 {
			local treat_l_`v' `treat_l_`v''\sym{*}
		}
		else if p_l_`v'> 0.1 {
			local treat_l_`v' `treat_l_`v''
		}
		
		if p_u_`v'< 0.01 {
			local treat_u_`v' `treat_u_`v''\sym{***}
		}
		else if 0.01<= p_u_`v' & p_u_`v' < 0.05 {
			local treat_u_`v' `treat_u_`v''\sym{**}
		}
		else if 0.05<= p_u_`v' & p_u_`v' < 0.1 {
			local treat_u_`v' `treat_u_`v''\sym{*}
		}
		else if p_u_`v'> 0.1 {
			local treat_u_`v' `treat_u_`v''
		}
	}

	local se
	foreach var in `vars'  {
		local se `se' se_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_l_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_u_`var'
	}
	
	foreach x in `se' {
		local `x'=trim(string(``x'',"%7.3f"))
	}





	local writetreatcol7`saveas' 
	local writetreat_lcol7`saveas'
 	local writetreat_ucol7`saveas' 
	local writesecol7`saveas'
	local writese_lcol7`saveas'
	local writese_ucol7`saveas' 
	local writeobscol7`saveas'
	local writeobs1col7`saveas'
	local writemistcol7`saveas'
	local writemisccol7`saveas'
	
	
	
	foreach var in `vars'  {
		local treat_`var' `treat_`var''
		local se_`var' `se_`var''
		local treat_l_`var' `treat_l_`var''
		local se_l_`var' `se_l_`var''
		local treat_u_`var' `treat_u_`var''
		local se_u_`var' `se_u_`var''
		local obs_`var' `obs_`var''
		local obs1_`var' `obs1_`var''
		local miss_t_`var' `missrate_t_`var''
		local miss_c_`var' `missrate_c_`var''
		
	local writetreatcol7`saveas' `writetreatcol7`saveas'' & `treat_`var''
	local writetreat_lcol7`saveas' `writetreat_lcol7`saveas'' & `treat_l_`var''
	local writetreat_ucol7`saveas' `writetreat_ucol7`saveas'' & `treat_u_`var''

	local writesecol7`saveas' `writesecol7`saveas'' & [`se_`var'']
	local writese_lcol7`saveas' `writese_lcol7`saveas'' & [`se_l_`var'']
	local writese_ucol7`saveas' `writese_ucol7`saveas'' & [`se_u_`var'']
	
	local writeobscol7`saveas' `writeobscol7`saveas'' & `obs_`var''
	local writeobs1col7`saveas' `writeobs1col7`saveas'' & `obs1_`var''
	local writemistcol7`saveas' `writemistcol7`saveas'' & `miss_t_`var''
	local writemisccol7`saveas' `writemisccol7`saveas'' & `miss_c_`var''

	}
restore	
	}


* Columns 1-5
{
use `table2dataset', clear
{
***** Iterate over the different pairwise groups

/*
	1. WCommHN Vs WHN 
	2. WCommHN Vs Control

*/

global pairgroup inlist(treat,2,1) inlist(treat,2,3)

foreach pair in $pairgroup {
	
preserve	
	* Keep pair-wise analysis groups
	keep if `pair'

	
	* Generate treatment variable
	gen treatvar=(treat==2)	
		local treatgroup "WCommHN"
		
		if "`pair'" =="inlist(treat,2,3)" {
			local saveas whn
			local controlgroupwhn "WHN"
			
		}
		if "`pair'" =="inlist(treat,2,1)" {
			local saveas cont
			local controlgroupcont "Control"
			
		}		
	* Dependent variables 
	local vars Ew_fp_talk_yno Ew_talk_hiv EWhusb_HnN_index Ew_plan_hhexpend12 Ew_marcomm_aste 

	gen B_treat_l=treatvar
	gen B_treat_u=treatvar
	
	lab var treatvar "`treatgroup'"
	lab var B_treat_l "`treatgroup' (Lower bound)"
	lab var B_treat_u "`treatgroup' (Upper bound)"

	local tablerow treatvar B_treat_l B_treat_u

	local varlab1: var lab treatvar
	local varlab2: var lab B_treat_l
	local varlab3: var lab B_treat_u

	summ treatvar if treatvar==1 
	local t_N = r(N) //count how many treatment observations we have
	summ treatvar if treatvar==0 
	local c_N = r(N) //count how many control observations we have

	summ treatvar 
	local all_N= r(N)
	
	
		di _n "*********************** Endline 3  ************************" _n
		di _n "Total : `all_N'"  _n			 
		di _n "Total control : `c_N'"  _n	
		di _n "Total treatment : `t_N'"  _n	
	
	gen miss = 0		
	local i=0
	set seed 412024
	gen x=runiform() // to break Lee bounds ties

	eststo clear
	foreach v in `vars' { // the local vars has the outcome variables of interest

		gen TLO_`v' = 0		// obsns to trim for lower bound
		gen TUP_`v' = 0		// obsns to trim for upper bound
		gen TABS_`v' = 0	// obsns to trim for lower bound in absolute value terms

		* final total obs by treatment and control
		local ft_N = `t_N'		
		local fc_N = `c_N'		

		

		
		
		*Leebounds
		
		if "`v'" == "Ew_fp_talk_yno" {
			areg `v' w_fp_talk_yno treatvar district1 district2 district3, absorb(stratum) cluster(villageid)
		}
		else if "`v'" == "Ew_talk_hiv" {
			areg `v' treatvar district1 district2 district3, absorb(stratum) cluster(villageid)
		}
		else if "`v'" == "EWhusb_HnN_index" {
			areg `v' treatvar district1 district2 district3, a(stratum) cluster(villageid)			
		}
		else if "`v'" == "Ew_plan_hhexpend12" {
			areg `v' w_plan_hhexpend6  treatvar district1 district2 district3, a(stratum) cluster(villageid)			
		}
		else if "`v'" == "Ew_marcomm_aste" {
			areg `v' w_marcomm_aste treatvar district1 district2 district3, a(stratum) cluster(villageid)			
		}

		
		local posneg = sign(_b[treatvar])	
		replace miss = (`v'== .)		// This is so when sorting data below and using _n, don't have to worry if Stata puts missing values first or last
		
		summ `v' if treatvar==1 
		local t_n = r(N)
		local t_rate = `t_n'/`ft_N'		// retention rate for treatment group
		
		summ `v' if treatvar==0 
		local c_n = r(N)
		local c_rate = `c_n'/`fc_N'		// retention rate for control group

		
		local trim_rate = abs(`c_rate' - `t_rate')	// % of obsns to trim
		

		
		* Missing rate 
		local t_miss =`ft_N' - `t_n'
		local c_miss =`fc_N' - `c_n'
		
		local t_miss_rate=`t_miss'/`ft_N'
		local c_miss_rate=`c_miss'/`fc_N'
		local missrate_t_`v': di %7.3fc  `t_miss_rate'
		local missrate_c_`v': di %7.3fc `c_miss_rate'

		di _n " " _n		
		di _n "Outcome : `v'" _n	
		di _n "		Non-Missing control : `c_n' & Non-Missing  treatment : `t_n'" _n		
		di _n "	            Treatment missing rate:  `t_miss_rate'" _n	
		di _n "             Control missing rate:  `c_miss_rate'" _n			
		di _n "             Trim rate:  `trim_rate'" _n	
	
		if `c_rate' > `t_rate' {  // trim from control group
			local trim_n = round(`trim_rate'* `fc_N')	// number of obsns to trim

			*cap confirm variable `v'			
			 gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat `v' x /*-B_S`v'*/
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 	// trim low values from control group to get lower bound
			
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x
			
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 
		}

		if `c_rate' < `t_rate' {  // trim from treat group
			local trim_n = round(`trim_rate'* `ft_N')	// number of obsns to trim
			di `trim_n'
			*cap confirm variable B_S`v'			
			gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat E_S`v' -B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0	*/ // trim low values from treat group to get upper bound
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x 
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0*/
		}		

		* Lower bound in absolute value terms depends on whether coefficient is positive or negative (unlikely to be exactly 0, but if so, full sample gives lower abs value bound)
		if `posneg'==1 {
			replace TABS_`v' = TLO_`v' 	// if treatment effect is positive, lower bound in absolute value terms is actual lower bound

		}
		if `posneg'==-1 {
			replace TABS_`v' = TUP_`v' // if treatment effect is negative, lower bound in absolute value terms is actual upper bound
		}		

		di _n "*****   Full sample   *****" _n		
		
		if "`v'" == "Ew_fp_talk_yno" {
			areg `v' w_fp_talk_yno treatvar district1 district2 district3, absorb(stratum) cluster(villageid)
		}
		else if "`v'" == "Ew_talk_hiv" {
			areg `v' treatvar district1 district2 district3, absorb(stratum) cluster(villageid)
		}
		else if "`v'" == "EWhusb_HnN_index" {
			areg `v' treatvar district1 district2 district3, a(stratum) cluster(villageid)			
		}
		else if "`v'" == "Ew_plan_hhexpend12" {
			areg `v' w_plan_hhexpend6  treatvar district1 district2 district3, a(stratum) cluster(villageid)			
		}
		else if "`v'" == "Ew_marcomm_aste" {
			areg `v' w_marcomm_aste treatvar district1 district2 district3, a(stratum) cluster(villageid)			
		}		
	
		
		local cluster_`v': di %7.0fc `e(N_clust)'
		local obs_`v': di %7.0fc `e(N)'
		local treat_`v': di %7.3fc _b[treatvar]
		local se_`v': di %7.3fc _se[treatvar]		
		local t_`v' = _b[treatvar]/_se[treatvar]
		scalar p_`v' = 2*ttail(e(df_r),abs(`t_`v''))

		dis "cluster_`v' : `cluster_`v''"
		dis "obs_`v' : `obs_`v''"
		dis "treat_`v' : `treat_`v''"
		dis "se_`v' : `se_`v''"
		dis "t_`v' : `t_`v''"
		dis "p`v' :"
		dis p_`v'
		
		
		
		di _n "*****   Lower bound   *****" _n
		
		if "`v'" == "Ew_fp_talk_yno" {
			areg `v' w_fp_talk_yno B_treat_l district1 district2 district3 if TLO_`v'==0, absorb(stratum) cluster(villageid)
		}
		else if "`v'" == "Ew_talk_hiv" {
			areg `v' B_treat_l district1 district2 district3 if TLO_`v'==0, absorb(stratum) cluster(villageid)
		}
		else if "`v'" == "EWhusb_HnN_index" {
			areg `v' B_treat_l district1 district2 district3 if TLO_`v'==0, a(stratum) cluster(villageid)			
		}
		else if "`v'" == "Ew_plan_hhexpend12" {
			areg `v' w_plan_hhexpend6  B_treat_l district1 district2 district3 if TLO_`v'==0, a(stratum) cluster(villageid)			
		}
		else if "`v'" == "Ew_marcomm_aste" {
			areg `v' w_marcomm_aste B_treat_l district1 district2 district3 if TLO_`v'==0, a(stratum) cluster(villageid)			
		}		

			
		local obs1_`v' : di %7.0fc `e(N)'
		local treat_l_`v': di %7.3fc _b[B_treat_l]
		local se_l_`v': di %7.3fc _se[B_treat_l]
		local t_l_`v' = _b[B_treat_l]/_se[B_treat_l]
		scalar p_l_`v' = 2*ttail(e(df_r),abs(`t_l_`v''))
		dis "obs_l_`v' : `obs_l_`v''"
		dis "treat_l_`v' : `treat_l_`v''"
		dis "se_l_`v' : `se_l_`v''"
		dis "t_l_`v' : `t_l_`v''"
		dis "p_l`v' :"
		dis p_l_`v'

		
		
		di _n "*****   Upper bound   *****" _n		
		if "`v'" == "Ew_fp_talk_yno" {
			areg `v' w_fp_talk_yno B_treat_u district1 district2 district3 if TUP_`v'==0, absorb(stratum) cluster(villageid)
		}
		else if "`v'" == "Ew_talk_hiv" {
			areg `v' B_treat_u district1 district2 district3 if TUP_`v'==0, absorb(stratum) cluster(villageid)
		}
		else if "`v'" == "EWhusb_HnN_index" {
			areg `v' B_treat_u district1 district2 district3 if TUP_`v'==0, a(stratum) cluster(villageid)			
		}
		else if "`v'" == "Ew_plan_hhexpend12" {
			areg `v' w_plan_hhexpend6  B_treat_u district1 district2 district3 if TUP_`v'==0, a(stratum) cluster(villageid)			
		}
		else if "`v'" == "Ew_marcomm_aste" {
			areg `v' w_marcomm_aste B_treat_u district1 district2 district3 if TUP_`v'==0, a(stratum) cluster(villageid)			
		}		
			
		
		local treat_u_`v': di %7.3fc _b[B_treat_u]
		local se_u_`v': di %7.3fc _se[B_treat_u]
		local t_u_`v' = _b[B_treat_u]/ _se[B_treat_u]
		scalar p_u_`v' = 2*ttail(e(df_r),abs(`t_u_`v''))
		dis p_u_`v'
		dis "obs_u_`v' : `obs_u_`v''"
		dis "treat_u_`v' : `treat_u_`v''"
		dis "se_u_`v' : `se_u_`v''"
		dis "t_u_`v' : `t_u_`v''"
		dis "p_u`v' :"
		dis p_u_`v'		
	

		di _n "*****   Bound on magnitude   *****" _n
		if "`v'" == "Ew_fp_talk_yno" {
			areg `v' w_fp_talk_yno treatvar district1 district2 district3 if TABS_`v'==0, absorb(stratum) cluster(villageid)
		}
		else if "`v'" == "Ew_talk_hiv" {
			areg `v' treatvar district1 district2 district3 if TABS_`v'==0, absorb(stratum) cluster(villageid)
		}
		else if "`v'" == "EWhusb_HnN_index" {
			areg `v' treatvar district1 district2 district3 if TABS_`v'==0, a(stratum) cluster(villageid)			
		}
		else if "`v'" == "Ew_plan_hhexpend12" {
			areg `v' w_plan_hhexpend6  treatvar district1 district2 district3 if TABS_`v'==0, a(stratum) cluster(villageid)			
		}
		else if "`v'" == "Ew_marcomm_aste" {
			areg `v' w_marcomm_aste treatvar district1 district2 district3 if TABS_`v'==0, a(stratum) cluster(villageid)			
		}				
				
		
		if p_`v'< 0.01 {
			local treat_`v' `treat_`v''\sym{***}
		}
		else if 0.01 <= p_`v' & p_`v' < 0.05 {
			local treat_`v' `treat_`v''\sym{**}
		}
		else if 0.05 <= p_`v' & p_`v' < 0.1 {
			local treat_`v' `treat_`v''\sym{*}
		}
		else if p_`v'> 0.1 {
			local treat_`v' `treat_`v''
		}
		
		if p_l_`v'< 0.01 {
			local treat_l_`v' `treat_l_`v''\sym{***}
		}
		else if 0.01<= p_l_`v' & p_l_`v' < 0.05 {
			local treat_l_`v' `treat_l_`v''\sym{**}
		}
		else if 0.05<= p_l_`v' & p_l_`v' < 0.1 {
			local treat_l_`v' `treat_l_`v''\sym{*}
		}
		else if p_l_`v'> 0.1 {
			local treat_l_`v' `treat_l_`v''
		}
		
		if p_u_`v'< 0.01 {
			local treat_u_`v' `treat_u_`v''\sym{***}
		}
		else if 0.01<= p_u_`v' & p_u_`v' < 0.05 {
			local treat_u_`v' `treat_u_`v''\sym{**}
		}
		else if 0.05<= p_u_`v' & p_u_`v' < 0.1 {
			local treat_u_`v' `treat_u_`v''\sym{*}
		}
		else if p_u_`v'> 0.1 {
			local treat_u_`v' `treat_u_`v''
		}
	}

	local se
	foreach var in `vars'  {
		local se `se' se_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_l_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_u_`var'
	}
	
	foreach x in `se' {
		local `x'=trim(string(``x'',"%7.3f"))
	}


	* header and no. of columns
	eststo clear
	local header
	local n_col =0
	foreach var in `vars'   {

		local varlab: variable label `var'
		local header "`header' & `varlab'" // column headers with variables labels 
		
		local ++n_col // number of columns		
		
	}


	local writetreat`saveas' `varlab1'
	local writetreat_l`saveas' `varlab2'
 	local writetreat_u`saveas' `varlab3'
	local writese`saveas'
	local writese_l`saveas'
	local writese_u`saveas' 
	local writeobs`saveas'
	local writeobs1`saveas'
	local writemist`saveas'
	local writemisc`saveas'
	
	
dis "writetreat`saveas' : `writetreat`saveas'' "
dis "writetreat_l`saveas' : `writetreat_l`saveas'' "
dis "writetreat_u`saveas' : `writetreat_u`saveas'' "
dis "writese_l`saveas' : `writese_l`saveas'' "
dis "writese_u`saveas' : `writese_u`saveas'' "
dis "writeobs`saveas' : `writeobs`saveas'' "
dis "writeobs1`saveas' : `writeobs1`saveas'' "

	foreach var in `vars'  {
		/*
		local treat_`var' `treat_`var''
		local se_`var' `se_`var''
		local treat_l_`var' `treat_l_`var''
		local se_l_`var' `se_l_`var''
		local treat_u_`var' `treat_u_`var''
		local se_u_`var' `se_u_`var''
		local obs_`var' `obs_`var''
		local obs1_`var' `obs1_`var''
		local miss_t_`var' `missrate_t_`var''
		local miss_c_`var' `missrate_c_`var''
		*/
	local writetreat`saveas' `writetreat`saveas'' & `treat_`var''
	local writetreat_l`saveas' `writetreat_l`saveas'' & `treat_l_`var''
	local writetreat_u`saveas' `writetreat_u`saveas'' & `treat_u_`var''

	local writese`saveas' `writese`saveas'' & [`se_`var'']
	local writese_l`saveas' `writese_l`saveas'' & [`se_l_`var'']
	local writese_u`saveas' `writese_u`saveas'' & [`se_u_`var'']
	
	local writeobs`saveas' `writeobs`saveas'' & `obs_`var''
	local writeobs1`saveas' `writeobs1`saveas'' & `obs1_`var''
	local writemist`saveas' `writemist`saveas'' & `missrate_t_`var''
	local writemisc`saveas' `writemisc`saveas'' & `missrate_c_`var''
	dis "`treat_l_`var''"
	dis "`writetreat`saveas''"
	}
	restore
			}
			
	dis "writemist`saveas' : `writemist`saveas'' "
dis "writemisc`saveas' : `writemisc`saveas'' "


	
	
* Layout options
	#d ;
	local frame "{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\renewcommand{\arraystretch}{rowspace}  
		\begin{tabular}{{>{\hangindent=1em}p{first}}*{colno}{>{\centering\arraybackslash}m{colspace}}}
		\toprule";
	#d cr	

	local frame0 = subinstr("`frame'", "first", "4.4cm", .) // first column width
	local frame1 = subinstr("`frame0'", "colspace", "1.6cm", .) // column spacing 
	local frame2 = subinstr("`frame1'", "rowspace", "1", .) // row spacing
	local prehead = subinstr("`frame2'", "colno", "7", .)	// number of columns		
	
		*** combined table
		cap file close regtab
		file open regtab using "$tables/table_A3b.tex", write replace
		
		
		file write regtab "`prehead' \\" _n      
		file write regtab "& Discusses family planning with spouse & Discusses HIV with spouse & Health and nutrition discussion ASTE & Discusses HH finance with spouse & Overall discussion ASTE & Health Knowledge ASTE (Woman) & Health Knowledge ASTE (Man) \\" _n 
		file write regtab "  & (1) & (2) & (3) & (4) & (5) & (6)  & (7)  \\    " _n    
	
			
			
		file write regtab "\midrule" _n 
		file write regtab "& \multicolumn{7}{c}{\textbf{WCommHN vs. Control}} \\" _n
		
		
		* Control
		file write regtab "\cmidrule(lr){2-8} `writetreat_lcont' `writetreat_lcol6cont' `writetreat_lcol7cont' \\  " _n	
		file write regtab  " `writese_lcont' `writese_lcol6cont' `writese_lcol7cont' \\  " _n
		

		file write regtab "`writetreat_ucont' `writetreat_ucol6cont' `writetreat_ucol7cont' \\  " _n	
		file write regtab  " `writese_ucont' `writese_ucol6cont' `writese_ucol7cont' \\  " _n		
		file write regtab "\midrule" _n 
		
		file write regtab "`treatgroup' missing rate `writemistcont' `writemistcol6cont' `writemistcol7cont' \\ " _n	
		file write regtab "`controlgroupcont' missing rate  `writemisccont' `writemisccol6cont' `writemisccol7cont' \\ " _n	
		
		
		* WHN
		file write regtab "\midrule" _n 
		file write regtab "& \multicolumn{7}{c}{\textbf{WCommHN vs. WHN}} \\" _n
		
		file write regtab "\cmidrule(lr){2-8} `writetreat_lwhn' `writetreat_lcol6whn' `writetreat_lcol7whn' \\  " _n	
		file write regtab  " `writese_lwhn' `writese_lcol6whn' `writese_lcol7whn' \\  " _n
		

		file write regtab " `writetreat_uwhn' `writetreat_ucol6whn' `writetreat_ucol7whn' \\  " _n	
		file write regtab  " `writese_uwhn' `writese_ucol6whn' `writese_ucol7whn' \\  " _n		
		file write regtab "\midrule" _n 
		
		file write regtab "`treatgroup' missing rate `writemistwhn' `writemistcol6whn' `writemistcol7whn' \\ " _n	
		file write regtab "`controlgroupwhn' missing rate  `writemiscwhn' `writemisccol6whn' `writemisccol7whn' \\ " _n			
		
		
				file write regtab "\bottomrule" _n           // table footer
		file write regtab "\end{tabular} }" _n 
		file close regtab		
			

			
		}

}
	
	
	
}	
	
*===============================================================================*			
* Table A.3c: Program impacts on household health behaviors: Lee bounds.
*===============================================================================*	
	
	if `table_a3c' == 1 {
				
	use "$analysis/womens_mens_mcm.dta", clear
		
	tab districtid, gen(district)
	drop district4		
	
	** 1) Newborn health variables				
					
	** Use this set of outcomes for Newborn Health ASTE: 
	
	local beh2 w_first_check_weeks_bi w_breastfeed w_breastfed_weeks_bi w_bfeed_atemore w_colostrum w_othliq_1week w_othliq_3mo w_food_3mo total_vacc vita_6wk vita_6mo
	local Ebeh2 Ew_first_check_weeks_bi Ew_breastfeed Ew_breastfed_weeks_bi Ew_bfeed_atemore Ew_colostrum Ew_othliq_1week Ew_othliq_3mo Ew_food_3mo Etotal_vacc Evita_6wk Evita_6mo 	
	
	** 2) Maternal health variables (only for mothers who are currently pregnant or have been pregnant in the past 2 years before endline)	
		// 3,860 endline pregnancies in past 2 years, including 780 current pregnancies
	
	* antenatal care
	
	cap drop Ew_latestpreg_ac2 w_latestpreg_ac2
	
	gen Ew_latestpreg_ac2 = Ew_lastpreg_ac if Ew_pregpast2 == 1 
		replace Ew_latestpreg_ac2 = Ew_preg_ac if Ew_pregnow == 1 & Ew_preg_ac!=. 
		
	gen w_latestpreg_ac2 = w_preg_ac2 if w_pregpast2 == 1
		replace w_latestpreg_ac2 = w_preg_ac if w_pregnow == 1 & w_preg_ac!=. 
	
	mdesc Ew_latestpreg_ac2 // 3641 non-missing values at endline
	cou if Ew_latestpreg_ac2!=. & w_latestpreg_ac2!=. // 3446 women have non-missing values for last pregnancy at endline *and* baseline values for same outcome
	
	* did woman eat more of certain foods during last pregnancy
	
	cap drop Ew_latestpreg_foods2 w_latestpreg_foods2	

	gen Ew_latestpreg_foods2 = Ew_lastpreg_foods if Ew_pregpast2 == 1 
		replace Ew_latestpreg_foods2 = Ew_preg_foods if Ew_pregnow == 1 & Ew_preg_foods!=. 
	
	gen w_latestpreg_foods2 = w_lastpreg_foods if w_pregpast2==1
		replace w_latestpreg_foods2 = w_preg_foods if w_pregnow==1 & w_preg_foods!=. 
		
	mdesc Ew_latestpreg_foods2 // 3638 non-missing values at endline
	cou if Ew_latestpreg_foods2!=. & w_latestpreg_foods2!=. // 3443 women have non-missing values for last pregnancy at endline *and* baseline values for same outcome
	
	* received iron during last pregnancy or in 2 months after // should be defined only for completed pregnancies in past 2 years 
			
	** Use this set of outcomes for Maternal Health ASTE: 
	
	local beh3 w_latestpreg_ac2 w_latestpreg_foods2 iron
	local Ebeh3 Ew_latestpreg_ac2 Ew_latestpreg_foods2 Eiron	
	
	** 3) Household sanitary practices variables
		
	** Use this set of outcomes for the Sanitary Practices ASTE: 
	
	local Ebeh1 Em_soap_toilet_bi Em_soap_meal_bi Ew_soap_toilet_bi Ew_soap_meal_bi Ew_treat_water Ew_toilet_sweep_bi Ew_toilet_improv
	local beh1 m_soap_toilet_bi m_soap_meal_bi w_soap_toilet_bi w_soap_meal_bi w_treat_water w_toilet_sweep_bi
	
	// ASTE 		
	forval i = 1/3 {		
		foreach var in `beh`i'' {
		cap confirm variable a_`var', exact
				if !_rc {
					drop a_`var'
				}			
		
		sum `var' if control == 1
			gen a_`var'=(`var'-`r(mean)')/`r(sd)'
		}
		foreach var in `Ebeh`i''  {
		cap confirm variable a_`var', exact
				if !_rc {
					drop a_`var'
				}				
			sum `var' if control == 1
			gen a_`var'=(`var'-`r(mean)')/`r(sd)'
		}
	}	
		
	** Column 1: Newborn Health ASTE
	
	cap drop aste_beh2 Easte_beh2

	local a_beh2 a_w_first_check_weeks_bi a_w_breastfeed a_w_breastfed_weeks_bi a_w_colostrum a_w_othliq_1week a_w_othliq_3mo a_w_food_3mo a_total_vacc a_vita_6wk a_vita_6mo a_w_bfeed_atemore
	local a_Ebeh2 a_Ew_first_check_weeks_bi a_Ew_breastfeed a_Ew_breastfed_weeks_bi a_Ew_colostrum a_Ew_othliq_1week a_Ew_othliq_3mo a_Ew_food_3mo a_Etotal_vacc a_Evita_6wk a_Evita_6mo a_Ew_bfeed_atemore
	
	mdesc `a_beh2' `a_Ebeh2'
	egen aste_beh2 = rowmean(`a_beh2')  
	egen Easte_beh2 = rowmean(`a_Ebeh2')  
	cou if Easte_beh2!=. & aste_beh2!=. // 3,034 non-missing obs
	
	** Column 2: Maternal Health ASTE
	
	cap drop aste_beh3 Easte_beh3 
	cap drop aste_beh0 Easte_beh0
	
	local a_beh3 a_w_latestpreg_ac2 a_w_latestpreg_foods2 a_iron
	local a_Ebeh3 a_Ew_latestpreg_ac2 a_Ew_latestpreg_foods2 a_Eiron
			
	mdesc `a_beh3' `a_Ebeh3'	
	egen aste_beh3 = rowmean(`a_beh3')  
	egen Easte_beh3 = rowmean(`a_Ebeh3')  
	
	** Column 3: Household Sanitary Practices ASTE
	
	cap drop aste_beh1 Easte_beh1
	
	local a_beh1 a_m_soap_toilet_bi a_m_soap_meal_bi a_w_soap_toilet_bi a_w_soap_meal_bi a_w_treat_water a_w_toilet_sweep_bi
	local a_Ebeh1 a_Em_soap_toilet_bi a_Em_soap_meal_bi a_Ew_soap_toilet_bi a_Ew_soap_meal_bi a_Ew_treat_water a_Ew_toilet_sweep_bi a_Ew_toilet_improv
	egen aste_beh1 = rowmean(`a_beh1')  
	egen Easte_beh1 = rowmean(`a_Ebeh1')  
	
	** Column 4: Overall health ASTE
	
	egen aste_beh0 = rowmean(`a_beh1' `a_beh2' `a_beh3')  
	egen Easte_beh0 = rowmean(`a_Ebeh1' `a_Ebeh2' `a_Ebeh3') 

	* Normalize ASTEs so that SD=1
	
	foreach var in aste_beh1 Easte_beh1 aste_beh2 Easte_beh2 aste_beh3 Easte_beh3 aste_beh0 Easte_beh0 {
		sum `var' if control==1
		replace `var'=(`var'-`r(mean)')/`r(sd)'				
	}	
				
	** Table 3, Health Behaviors
	
	estimates clear
	local controls district? 
	local covars wemp whn mhn
	lab var wemp "WCommHN"

	foreach y in aste_beh2 aste_beh3 aste_beh1 aste_beh0 { // maternal health, hygiene, overall ASTE: columns (2), (3), (4)
		eststo est`y': areg E`y' `y' `covars' `controls', absorb(stratum) cluster(villageid)		
		sum E`y' if e(sample)==1 & control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`y'
		test whn=wemp
			estadd scalar pval1=r(p): est`y'
		test wemp=mhn
			estadd scalar pval2=r(p): est`y'
		test whn=mhn
			estadd scalar pval3=r(p): est`y'	
	}
	
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*								Lee-Bounds 										*	
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *	
{
***** Iterate over the different pairwise groups
decode treat, gen(treatstring)

/*
	1. WCommHN Vs WHN 
	2. WCommHN Vs Control

*/

global pairgroup inlist(treat,2,1) inlist(treat,2,3)

foreach pair in $pairgroup {
	
preserve	
	* Keep pair-wise analysis groups
	keep if `pair'
	
	* Generate treatment variable
	gen treatvar=(treat==2)	
		local treatgroup "WCommHN"
		
		if "`pair'" =="inlist(treat,2,3)" {
			local saveas whn
			local controlgroupwhn "WHN"
			
		}
		if "`pair'" =="inlist(treat,2,1)" {
			local saveas cont
			local controlgroupcont "Control"
			
		}	
	* Dependent variables 
	local vars Easte_beh2 Easte_beh3 Easte_beh1 Easte_beh0	

	gen B_treat_l=treatvar
	gen B_treat_u=treatvar
	
	lab var treatvar "`treatgroup'"
	lab var B_treat_l "`treatgroup' (Lower bound)"
	lab var B_treat_u "`treatgroup' (Upper bound)"

	local tablerow treatvar B_treat_l B_treat_u

	local varlab1: var lab treatvar
	local varlab2: var lab B_treat_l
	local varlab3: var lab B_treat_u

	summ treatvar if treatvar==1 
	local t_N = r(N) //count how many treatment observations we have
	summ treatvar if treatvar==0 
	local c_N = r(N) //count how many control observations we have

	summ treatvar 
	local all_N= r(N)
	
	
		di _n "*********************** Endline 3  ************************" _n
		di _n "Total : `all_N'"  _n			 
		di _n "Total control : `c_N'"  _n	
		di _n "Total treatment : `t_N'"  _n	
	
	gen miss = 0		
	local i=0
	set seed 412024
	gen x=runiform() // to break Lee bounds ties

	eststo clear
	foreach v in `vars' { // the local vars has the outcome variables of interest

		gen TLO_`v' = 0		// obsns to trim for lower bound
		gen TUP_`v' = 0		// obsns to trim for upper bound
		gen TABS_`v' = 0	// obsns to trim for lower bound in absolute value terms

		* final total obs by treatment and control
		local ft_N = `t_N'		
		local fc_N = `c_N'		

		
		*Leebounds
		
		* Confirm if there is a variable in baseline to control for
		local ldv`v'= substr("`v'",2,.)		
		
		
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' treatvar district1 district2 district3 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  treatvar district1 district2 district3 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}

	
		local posneg = sign(_b[treatvar])	// Is treatment effect with untrimmed sample positive or negative?
		replace miss = (`v'== .)		// This is so when sorting data below and using _n, don't have to worry if Stata puts missing values first or last
		
		summ `v' if treatvar==1 
		local t_n = r(N)
		local t_rate = `t_n'/`ft_N'		// retention rate for treatment group
		
		summ `v' if treatvar==0 
		local c_n = r(N)
		local c_rate = `c_n'/`fc_N'		// retention rate for control group

		local trim_rate = abs(`c_rate' - `t_rate')	// % of obsns to trim
		
		
		* Missing rate 
		local t_miss =`ft_N' - `t_n'
		local c_miss =`fc_N' - `c_n'
		
		local t_miss_rate=`t_miss'/`ft_N'
		local c_miss_rate=`c_miss'/`fc_N'
		local missrate_t_`v': di %7.3fc  `t_miss_rate'
		local missrate_c_`v': di %7.3fc `c_miss_rate'

		di _n " " _n		
		di _n "Outcome : `v'" _n	
		di _n "		Non-Missing control : `c_n' & Non-Missing  treatment : `t_n'" _n		
		di _n "	            Treatment missing rate:  `t_miss_rate'" _n	
		di _n "             Control missing rate:  `c_miss_rate'" _n			
		di _n "             Trim rate:  `trim_rate'" _n	
	
		if `c_rate' > `t_rate' {  // trim from control group
			local trim_n = round(`trim_rate'* `fc_N')	// number of obsns to trim

			*cap confirm variable `v'			
			 gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat `v' x /*-B_S`v'*/
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 	// trim low values from control group to get lower bound
			
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x
			
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 
		}

		if `c_rate' < `t_rate' {  // trim from treat group
			local trim_n = round(`trim_rate'* `ft_N')	// number of obsns to trim
			di `trim_n'
			*cap confirm variable B_S`v'			
			gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat E_S`v' -B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0	*/ // trim low values from treat group to get upper bound
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x 
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0*/
		}		

		* Lower bound in absolute value terms depends on whether coefficient is positive or negative (unlikely to be exactly 0, but if so, full sample gives lower abs value bound)
		if `posneg'==1 {
			replace TABS_`v' = TLO_`v' 	// if treatment effect is positive, lower bound in absolute value terms is actual lower bound

		}
		if `posneg'==-1 {
			replace TABS_`v' = TUP_`v' // if treatment effect is negative, lower bound in absolute value terms is actual upper bound
		}		

		di _n "*****   Full sample   *****" _n		
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' treatvar district1 district2 district3 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  treatvar district1 district2 district3 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		
		local cluster_`v': di %7.0fc `e(N_clust)'
		local obs_`v': di %7.0fc `e(N)'
		local treat_`v': di %7.3fc _b[treatvar]
		local se_`v': di %7.3fc _se[treatvar]		
		local t_`v' = _b[treatvar]/_se[treatvar]
		scalar p_`v' = 2*ttail(e(df_r),abs(`t_`v''))

		dis "cluster_`v' : `cluster_`v''"
		dis "obs_`v' : `obs_`v''"
		dis "treat_`v' : `treat_`v''"
		dis "se_`v' : `se_`v''"
		dis "t_`v' : `t_`v''"
		dis "p`v' :"
		dis p_`v'
		
		di _n "*****   Lower bound   *****" _n
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' B_treat_l district1 district2 district3 if TLO_`v'==0, 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  B_treat_l district1 district2 district3 if TLO_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		
		local obs1_`v' : di %7.0fc `e(N)'
		local treat_l_`v': di %7.3fc _b[B_treat_l]
		local se_l_`v': di %7.3fc _se[B_treat_l]
		local t_l_`v' = _b[B_treat_l]/_se[B_treat_l]
		scalar p_l_`v' = 2*ttail(e(df_r),abs(`t_l_`v''))
		dis "obs_l_`v' : `obs_l_`v''"
		dis "treat_l_`v' : `treat_l_`v''"
		dis "se_l_`v' : `se_l_`v''"
		dis "t_l_`v' : `t_l_`v''"
		dis "p_l`v' :"
		dis p_l_`v'

		
		di _n "*****   Upper bound   *****" _n		
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' B_treat_u district1 district2 district3 if TUP_`v'==0, 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  B_treat_u district1 district2 district3 if TUP_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		
		
		local treat_u_`v': di %7.3fc _b[B_treat_u]
		local se_u_`v': di %7.3fc _se[B_treat_u]
		local t_u_`v' = _b[B_treat_u]/ _se[B_treat_u]
		scalar p_u_`v' = 2*ttail(e(df_r),abs(`t_u_`v''))
		dis p_u_`v'
		dis "obs_u_`v' : `obs_u_`v''"
		dis "treat_u_`v' : `treat_u_`v''"
		dis "se_u_`v' : `se_u_`v''"
		dis "t_u_`v' : `t_u_`v''"
		dis "p_u`v' :"
		dis p_u_`v'		
	

		di _n "*****   Bound on magnitude   *****" _n
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' treatvar district1 district2 district3 if TABS_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  treatvar district1 district2 district3 if TABS_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}	
	
		
		if p_`v'< 0.01 {
			local treat_`v' `treat_`v''\sym{***}
		}
		else if 0.01 <= p_`v' & p_`v' < 0.05 {
			local treat_`v' `treat_`v''\sym{**}
		}
		else if 0.05 <= p_`v' & p_`v' < 0.1 {
			local treat_`v' `treat_`v''\sym{*}
		}
		else if p_`v'> 0.1 {
			local treat_`v' `treat_`v''
		}
		
		if p_l_`v'< 0.01 {
			local treat_l_`v' `treat_l_`v''\sym{***}
		}
		else if 0.01<= p_l_`v' & p_l_`v' < 0.05 {
			local treat_l_`v' `treat_l_`v''\sym{**}
		}
		else if 0.05<= p_l_`v' & p_l_`v' < 0.1 {
			local treat_l_`v' `treat_l_`v''\sym{*}
		}
		else if p_l_`v'> 0.1 {
			local treat_l_`v' `treat_l_`v''
		}
		
		if p_u_`v'< 0.01 {
			local treat_u_`v' `treat_u_`v''\sym{***}
		}
		else if 0.01<= p_u_`v' & p_u_`v' < 0.05 {
			local treat_u_`v' `treat_u_`v''\sym{**}
		}
		else if 0.05<= p_u_`v' & p_u_`v' < 0.1 {
			local treat_u_`v' `treat_u_`v''\sym{*}
		}
		else if p_u_`v'> 0.1 {
			local treat_u_`v' `treat_u_`v''
		}
	}

	local se
	foreach var in `vars'  {
		local se `se' se_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_l_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_u_`var'
	}
	
	foreach x in `se' {
		local `x'=trim(string(``x'',"%7.3f"))
	}


	* header and no. of columns
	eststo clear
	local header
	local n_col =0
	foreach var in `vars'   {

		local varlab: variable label `var'
		local header "`header' & `varlab'" // column headers with variables labels 
		
		local ++n_col // number of columns		
		
	}


	local writetreat`saveas' `varlab1'
	local writetreat_l`saveas' `varlab2'
 	local writetreat_u`saveas' `varlab3'
	local writese`saveas'
	local writese_l`saveas'
	local writese_u`saveas' 
	local writeobs`saveas'
	local writeobs1`saveas'
	local writemist`saveas'
	local writemisc`saveas'
	
	
	
	foreach var in `vars'  {
		local treat_`var' `treat_`var''
		local se_`var' `se_`var''
		local treat_l_`var' `treat_l_`var''
		local se_l_`var' `se_l_`var''
		local treat_u_`var' `treat_u_`var''
		local se_u_`var' `se_u_`var''
		local obs_`var' `obs_`var''
		local obs1_`var' `obs1_`var''
		local miss_t_`var' `missrate_t_`var''
		local miss_c_`var' `missrate_c_`var''
		
	local writetreat`saveas' `writetreat`saveas'' & `treat_`var''
	local writetreat_l`saveas' `writetreat_l`saveas'' & `treat_l_`var''
	local writetreat_u`saveas' `writetreat_u`saveas'' & `treat_u_`var''

	local writese`saveas' `writese`saveas'' & [`se_`var'']
	local writese_l`saveas' `writese_l`saveas'' & [`se_l_`var'']
	local writese_u`saveas' `writese_u`saveas'' & [`se_u_`var'']
	
	local writeobs`saveas' `writeobs`saveas'' & `obs_`var''
	local writeobs1`saveas' `writeobs1`saveas'' & `obs1_`var''
	local writemist`saveas' `writemist`saveas'' & `miss_t_`var''
	local writemisc`saveas' `writemisc`saveas'' & `miss_c_`var''

	}
	dis "`writetreat'"

	restore
			}
	
* Layout options
	#d ;
	local frame "{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\renewcommand{\arraystretch}{rowspace}  
		\begin{tabular}{{>{\hangindent=1em}p{first}}*{colno}{>{\centering\arraybackslash}m{colspace}}}
		\toprule";
	#d cr	

	local frame0 = subinstr("`frame'", "first", "5.5cm", .) // first column width
	local frame1 = subinstr("`frame0'", "colspace", "2.4cm", .) // column spacing 
	local frame2 = subinstr("`frame1'", "rowspace", "1", .) // row spacing
	local prehead = subinstr("`frame2'", "colno", "4", .)	// number of columns		
	
		*** combined table
		cap file close regtab
		file open regtab using "$tables/table_A3c.tex", write replace
		
		file write regtab "`prehead' \\" _n      
		file write regtab "& Newborn health ASTE & Maternal health ASTE & Sanitary practices ASTE & Overall health ASTE \\" _n
		file write regtab "  & (1) & (2) & (3) & (4) \\    " _n    
	
		file write regtab "\midrule" _n 
		file write regtab "& \multicolumn{4}{c}{\textbf{WCommHN vs. Control}} \\" _n
		
		* Control
		file write regtab "\cmidrule(lr){2-5} `writetreat_lcont' \\  " _n	
		file write regtab  " `writese_lcont' \\  " _n
		
		file write regtab "`writetreat_ucont' \\  " _n	
		file write regtab  "`writese_ucont' \\  " _n		
		file write regtab "\midrule" _n 
		
		file write regtab "`treatgroup' missing rate `writemistcont' \\ " _n	
		file write regtab "`controlgroupcont' missing rate  `writemisccont' \\ " _n	
		
		* WHN
		file write regtab "\midrule" _n 
		file write regtab "& \multicolumn{4}{c}{\textbf{WCommHN vs. WHN}} \\" _n
		
		file write regtab "\cmidrule(lr){2-5} `writetreat_lwhn' \\  " _n	
		file write regtab  " `writese_lwhn' \\  " _n		

		file write regtab "`writetreat_uwhn' \\  " _n	
		file write regtab  "`writese_uwhn' \\  " _n		

		file write regtab "\midrule" _n 
		
		file write regtab "`treatgroup' missing rate  `writemistwhn' \\ " _n	
		file write regtab "`controlgroupwhn' missing rate  `writemiscwhn' \\ " _n			
		
	
	
	
	
		file write regtab "\bottomrule" _n           // table footer
		file write regtab "\end{tabular} }" _n 
		file close regtab	
	
	
	
		}

}			
	
*===============================================================================*			
* Table A.3d: Program impacts on women's and children's nutrition: Lee bounds.
*===============================================================================*	

	if `table_a3d' == 1 {
	
	* Panel A.
	{
	use "$analysis/womens_mens_mcm.dta", clear
	
	tab districtid, gen(district)
	drop district4	
	
	eststo clear
	estimates clear

	*** Panel A: FOOD INTAKE (WOMEN AND CHILDREN)
			
	** Generate standardized variables for ASTE indices (WOMEN):
			
	foreach var in w_milk w_water w_tea w_juice w_otherbev w_matooke w_roots w_grains w_organ w_meat w_egg w_fish w_green w_pump w_otherfru {
	cap confirm variable B`var', exact
	if !_rc {
			drop B`var'
	}
	cap confirm variable EE`var', exact
	if !_rc {
			drop EE`var'
	}	
		sum `var' if control == 1
		gen B`var'=(`var'-`r(mean)')/`r(sd)'
		sum E`var' if control == 1
		gen EE`var'=(E`var'-`r(mean)')/`r(sd)'
	}	
		
	preserve
		use "$analysis/child_level_mcm.dta", clear
		
		tab districtid, gen(district)
		drop district4	
		
		collapse (mean) Emilk Ewater Etea Ejuice Eotherbev Ematooke Eroots Egrains Eorgan Emeat Ebeans Eegg Efish Egreen Epump Eotherfru ///
			milk water tea juice otherbev matooke roots grains organ meat beans egg fish green pump otherfru, by(id control) 	
		
		save "$intermediate\foraste.dta", replace
	restore 
	
	merge 1:1 id using "$intermediate\foraste.dta", keep(match) nogen
	
	** Generate standardized variables for ASTE indices (CHILDREN):
			
	foreach var in milk water tea juice otherbev matooke roots grains organ meat egg fish green pump otherfru {
	cap confirm variable B`var', exact
	if !_rc {
			drop B`var'
	}
	cap confirm variable EE`var', exact
	if !_rc {
			drop EE`var'
	}		
		sum `var' if control == 1
		gen B`var'=(`var'-`r(mean)')/`r(sd)'
		sum E`var' if control == 1
		gen EE`var'=(E`var'-`r(mean)')/`r(sd)'
	}	
			
		*1) Beverages ASTE 
	cap drop bev_aste Ebev_aste	
		
	egen bev_aste = rowmean(Bmilk Bwater Btea Bjuice Botherbev Bw_milk Bw_water Bw_tea Bw_juice Bw_otherbev)	
	egen Ebev_aste = rowmean(EEmilk EEwater EEtea EEjuice EEotherbev EEw_milk EEw_water EEw_tea EEw_juice EEw_otherbev)		
		
		*2) Carbohydrates ASTE
	cap drop carb_aste Ecarb_aste	

	egen carb_aste = rowmean(Bmatooke Broots Bgrains Bw_matooke Bw_roots Bw_grains)	
	egen Ecarb_aste = rowmean(EEmatooke EEroots EEgrains EEw_matooke EEw_roots EEw_grains)		

		*3) Protein-rich foods ASTE
	cap drop protein_aste Eprotein_aste		
	
	egen protein_aste = rowmean(Borgan Bmeat Begg Bfish Bw_organ Bw_meat Bw_egg Bw_fish)	
	egen Eprotein_aste = rowmean(EEorgan EEmeat EEegg EEfish EEw_organ EEw_meat EEw_egg EEw_fish)		
	
		*4) Fruit and Veg ASTE
	cap drop fruitveg_aste Efruitveg_aste	

	egen fruitveg_aste = rowmean(Bgreen Bpump Botherfru Bw_green Bw_pump Bw_otherfru)	
	egen Efruitveg_aste = rowmean(EEgreen EEpump EEotherfr EEw_green EEw_pump EEw_otherfr)		

	* Normalize ASTEs so that SD=1
	foreach var in carb_aste protein_aste fruitveg_aste {
		sum `var' if control==1
		replace `var'=(`var'-`r(mean)')/`r(sd)'				
		sum E`var' if control==1
		replace E`var'=(E`var'-`r(mean)')/`r(sd)'				
	}	
	
	
	***** Iterate over the different pairwise groups
decode treat, gen(treatstring)

/*
	1. WCommHN Vs WHN 
	2. WCommHN Vs Control

*/

global pairgroup inlist(treat,2,1) inlist(treat,2,3)

foreach pair in $pairgroup {
	
preserve	
	* Keep pair-wise analysis groups
	keep if `pair'
	
	* Generate treatment variable
	gen treatvar=(treat==2)	
	local treatgroup "WCommHN"
		
		
		if "`pair'" =="inlist(treat,2,3)" {
			local saveas whn
			local controlgroupwhn "WHN"
			
		}
		if "`pair'" =="inlist(treat,2,1)" {
			local saveas cont
			local controlgroupcont "Control"
			
		}	
		
	* Dependent variables 
	local vars Ecarb_aste Eprotein_aste Efruitveg_aste

	gen B_treat_l=treatvar
	gen B_treat_u=treatvar
	
	lab var treatvar "`treatgroup'"
	lab var B_treat_l "`treatgroup' (Lower bound)"
	lab var B_treat_u "`treatgroup' (Upper bound)"

	local tablerow treatvar B_treat_l B_treat_u

	local varlab1: var lab treatvar
	local varlab2: var lab B_treat_l
	local varlab3: var lab B_treat_u

	summ treatvar if treatvar==1 
	local t_N = r(N) //count how many treatment observations we have
	summ treatvar if treatvar==0 
	local c_N = r(N) //count how many control observations we have

	summ treatvar 
	local all_N= r(N)
	
	
		di _n "*********************** Endline 3  ************************" _n
		di _n "Total : `all_N'"  _n			 
		di _n "Total control : `c_N'"  _n	
		di _n "Total treatment : `t_N'"  _n	
	
	gen miss = 0		
	local i=0
	set seed 412024
	gen x=runiform() // to break Lee bounds ties

	eststo clear
	foreach v in `vars' { // the local vars has the outcome variables of interest

		gen TLO_`v' = 0		// obsns to trim for lower bound
		gen TUP_`v' = 0		// obsns to trim for upper bound
		gen TABS_`v' = 0	// obsns to trim for lower bound in absolute value terms

		* final total obs by treatment and control
		local ft_N = `t_N'		
		local fc_N = `c_N'		

		
		*Leebounds
		
		* Confirm if there is a variable in baseline to control for
		local ldv`v'= substr("`v'",2,.)		
		
		
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' treatvar district1 district2 district3 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  treatvar district1 district2 district3 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}

	
		local posneg = sign(_b[treatvar])	// Is treatment effect with untrimmed sample positive or negative?
		replace miss = (`v'== .)		// This is so when sorting data below and using _n, don't have to worry if Stata puts missing values first or last
		
		summ `v' if treatvar==1 
		local t_n = r(N)
		local t_rate = `t_n'/`ft_N'		// retention rate for treatment group
		
		summ `v' if treatvar==0 
		local c_n = r(N)
		local c_rate = `c_n'/`fc_N'		// retention rate for control group

		
		local trim_rate = abs(`c_rate' - `t_rate')	// % of obsns to trim
		

		
		* Missing rate 
		local t_miss =`ft_N' - `t_n'
		local c_miss =`fc_N' - `c_n'
		
		local t_miss_rate=`t_miss'/`ft_N'
		local c_miss_rate=`c_miss'/`fc_N'
		local missrate_t_`v': di %7.3fc  `t_miss_rate'
		local missrate_c_`v': di %7.3fc `c_miss_rate'

		di _n " " _n		
		di _n "Outcome : `v'" _n	
		di _n "		Non-Missing control : `c_n' & Non-Missing  treatment : `t_n'" _n		
		di _n "	            Treatment missing rate:  `t_miss_rate'" _n	
		di _n "             Control missing rate:  `c_miss_rate'" _n			
		di _n "             Trim rate:  `trim_rate'" _n	
	
		if `c_rate' > `t_rate' {  // trim from control group
			local trim_n = round(`trim_rate'* `fc_N')	// number of obsns to trim

			*cap confirm variable `v'			
			 gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat `v' x /*-B_S`v'*/
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 	// trim low values from control group to get lower bound
			
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x
			
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 
		}

		if `c_rate' < `t_rate' {  // trim from treat group
			local trim_n = round(`trim_rate'* `ft_N')	// number of obsns to trim
			di `trim_n'
			*cap confirm variable B_S`v'			
			gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat E_S`v' -B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0	*/ // trim low values from treat group to get upper bound
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x 
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0*/
		}		

		* Lower bound in absolute value terms depends on whether coefficient is positive or negative (unlikely to be exactly 0, but if so, full sample gives lower abs value bound)
		if `posneg'==1 {
			replace TABS_`v' = TLO_`v' 	// if treatment effect is positive, lower bound in absolute value terms is actual lower bound

		}
		if `posneg'==-1 {
			replace TABS_`v' = TUP_`v' // if treatment effect is negative, lower bound in absolute value terms is actual upper bound
		}		

		di _n "*****   Full sample   *****" _n		
	
		* Confirm if there is a variable in baseline to control for
		local ldv`v'= substr("`v'",2,.)		
		
		
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' treatvar district1 district2 district3 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  treatvar district1 district2 district3 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		
		
		local cluster_`v': di %7.0fc `e(N_clust)'
		local obs_`v': di %7.0fc `e(N)'
		local treat_`v': di %7.3fc _b[treatvar]
		local se_`v': di %7.3fc _se[treatvar]		
		local t_`v' = _b[treatvar]/_se[treatvar]
		scalar p_`v' = 2*ttail(e(df_r),abs(`t_`v''))

		dis "cluster_`v' : `cluster_`v''"
		dis "obs_`v' : `obs_`v''"
		dis "treat_`v' : `treat_`v''"
		dis "se_`v' : `se_`v''"
		dis "t_`v' : `t_`v''"
		dis "p`v' :"
		dis p_`v'
		
		
		
		di _n "*****   Lower bound   *****" _n
	
* Confirm if there is a variable in baseline to control for
		local ldv`v'= substr("`v'",2,.)		
		
		
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' B_treat_l district1 district2 district3 if TLO_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  B_treat_l district1 district2 district3 if TLO_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}

		
		
		local obs1_`v' : di %7.0fc `e(N)'
		local treat_l_`v': di %7.3fc _b[B_treat_l]
		local se_l_`v': di %7.3fc _se[B_treat_l]
		local t_l_`v' = _b[B_treat_l]/_se[B_treat_l]
		scalar p_l_`v' = 2*ttail(e(df_r),abs(`t_l_`v''))
		dis "obs_l_`v' : `obs_l_`v''"
		dis "treat_l_`v' : `treat_l_`v''"
		dis "se_l_`v' : `se_l_`v''"
		dis "t_l_`v' : `t_l_`v''"
		dis "p_l`v' :"
		dis p_l_`v'

		
		
		di _n "*****   Upper bound   *****" _n		
		local ldv`v'= substr("`v'",2,.)		
		
		
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' B_treat_u district1 district2 district3 if TUP_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  B_treat_u district1 district2 district3 if TUP_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		
		
		local treat_u_`v': di %7.3fc _b[B_treat_u]
		local se_u_`v': di %7.3fc _se[B_treat_u]
		local t_u_`v' = _b[B_treat_u]/ _se[B_treat_u]
		scalar p_u_`v' = 2*ttail(e(df_r),abs(`t_u_`v''))
		dis p_u_`v'
		dis "obs_u_`v' : `obs_u_`v''"
		dis "treat_u_`v' : `treat_u_`v''"
		dis "se_u_`v' : `se_u_`v''"
		dis "t_u_`v' : `t_u_`v''"
		dis "p_u`v' :"
		dis p_u_`v'		
	

		di _n "*****   Bound on magnitude   *****" _n
		local ldv`v'= substr("`v'",2,.)		
		
		
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' treatvar district1 district2 district3 if TABS_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  treatvar district1 district2 district3 if TABS_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}

		
		
		if p_`v'< 0.01 {
			local treat_`v' `treat_`v''\sym{***}
		}
		else if 0.01 <= p_`v' & p_`v' < 0.05 {
			local treat_`v' `treat_`v''\sym{**}
		}
		else if 0.05 <= p_`v' & p_`v' < 0.1 {
			local treat_`v' `treat_`v''\sym{*}
		}
		else if p_`v'> 0.1 {
			local treat_`v' `treat_`v''
		}
		
		if p_l_`v'< 0.01 {
			local treat_l_`v' `treat_l_`v''\sym{***}
		}
		else if 0.01<= p_l_`v' & p_l_`v' < 0.05 {
			local treat_l_`v' `treat_l_`v''\sym{**}
		}
		else if 0.05<= p_l_`v' & p_l_`v' < 0.1 {
			local treat_l_`v' `treat_l_`v''\sym{*}
		}
		else if p_l_`v'> 0.1 {
			local treat_l_`v' `treat_l_`v''
		}
		
		if p_u_`v'< 0.01 {
			local treat_u_`v' `treat_u_`v''\sym{***}
		}
		else if 0.01<= p_u_`v' & p_u_`v' < 0.05 {
			local treat_u_`v' `treat_u_`v''\sym{**}
		}
		else if 0.05<= p_u_`v' & p_u_`v' < 0.1 {
			local treat_u_`v' `treat_u_`v''\sym{*}
		}
		else if p_u_`v'> 0.1 {
			local treat_u_`v' `treat_u_`v''
		}
	}

	local se
	foreach var in `vars'  {
		local se `se' se_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_l_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_u_`var'
	}
	
	foreach x in `se' {
		local `x'=trim(string(``x'',"%7.3f"))
	}





	local writetreatA`saveas' `varlab1'
	local writetreat_lA`saveas' `varlab2'
 	local writetreat_uA`saveas' `varlab3'
	local writeseA`saveas'
	local writese_lA`saveas'
	local writese_uA`saveas' 
	local writeobsA`saveas'
	local writeobs1A`saveas'
	local writemistA`saveas'
	local writemiscA`saveas'
	
	
	
	foreach var in `vars'  {
		local treat_`var' `treat_`var''
		local se_`var' `se_`var''
		local treat_l_`var' `treat_l_`var''
		local se_l_`var' `se_l_`var''
		local treat_u_`var' `treat_u_`var''
		local se_u_`var' `se_u_`var''
		local obs_`var' `obs_`var''
		local obs1_`var' `obs1_`var''
		local miss_t_`var' `missrate_t_`var''
		local miss_c_`var' `missrate_c_`var''
		
	local writetreatA`saveas' `writetreatA`saveas'' & `treat_`var''
	local writetreat_lA`saveas' `writetreat_lA`saveas'' & `treat_l_`var''
	local writetreat_uA`saveas' `writetreat_uA`saveas'' & `treat_u_`var''

	local writeseA`saveas' `writeseA`saveas'' & [`se_`var'']
	local writese_lA`saveas' `writese_lA`saveas'' & [`se_l_`var'']
	local writese_uA`saveas' `writese_uA`saveas'' & [`se_u_`var'']
	
	local writeobsA`saveas' `writeobsA`saveas'' & `obs_`var''
	local writeobs1A`saveas' `writeobs1A`saveas'' & `obs1_`var''
	local writemistA`saveas' `writemistA`saveas'' & `miss_t_`var''
	local writemiscA`saveas' `writemiscA`saveas'' & `miss_c_`var''

	}
	dis "`writetreat'"
restore
	}
			

			
			
}
	
	* Panel B.
	{
use "$analysis/womens_mens_mcm.dta", clear
	
	tab districtid, gen(district)
	drop district4	
	
	** Crop rotation on plots
	
	cap drop Ew_growmoreveg_12mo
	gen Ew_growmoreveg_12mo=Ew_change_crops_how1
	replace Ew_growmoreveg_12mo=0 if Ew_change_crops==0 // if HH didn't change crop composition in the last 12 months, they are not growing more fruit and veg
	
	** Expenditure
	
	cap drop Ehh_num_member 
	recode Ew_num_adults (18=.) // plausible outlier
	gen Ehh_num_member = Ew_num_adults + 0.5*Em_hhkids_num
	cap drop hh_num_member
	gen hh_num_member = w_num_adults + 0.5*w_numkids18

	*endline
	foreach y in meats rice {
	cap confirm variable Ew_exp_`y', exact
	if !_rc {
			drop  Ew_exp_`y'
	}			
		gen Ew_exp_`y' = Ew_last7d_`y'/Ehh_num_member
	}	
	cap drop Ew_exp_protein
	ren Ew_exp_meats Ew_exp_protein
	
	*baseline
	cap drop w_exp_protein w_exp_rice	
	gen w_exp_protein=w_mtfs_own/hh_num_member	
	gen w_rice_7d=w_last6m_rice/181
	gen w_exp_rice=w_rice_7d/hh_num_member	
	
	foreach y in rice protein  {
		sum w_exp_`y', d
		replace w_exp_`y' = . if w_exp_`y'>`r(p99)'
		sum Ew_exp_`y', d
		replace Ew_exp_`y' = . if Ew_exp_`y'>`r(p99)'
	}
	
	
	***** Iterate over the different pairwise groups
decode treat, gen(treatstring)

/*
	1. WCommHN Vs WHN 
	2. WCommHN Vs Control

*/

global pairgroup inlist(treat,2,1) inlist(treat,2,3)

foreach pair in $pairgroup {
	
preserve	
	* Keep pair-wise analysis groups
	keep if `pair'
	
	* Generate treatment variable
	gen treatvar=(treat==2)	
		local treatgroup "WCommHN"
		
		if "`pair'" =="inlist(treat,2,3)" {
			local saveas whn
			local controlgroupwhn "WHN"
			
		}
		if "`pair'" =="inlist(treat,2,1)" {
			local saveas cont
			local controlgroupcont "Control"
			
		}	
	* Dependent variables 
	local vars Ew_exp_rice Ew_exp_protein Ew_growmoreveg_12mo

	gen B_treat_l=treatvar
	gen B_treat_u=treatvar
	
	lab var treatvar "`treatgroup'"
	lab var B_treat_l "`treatgroup' (Lower bound)"
	lab var B_treat_u "`treatgroup' (Upper bound)"

	local tablerow treatvar B_treat_l B_treat_u

	local varlab1: var lab treatvar
	local varlab2: var lab B_treat_l
	local varlab3: var lab B_treat_u

	summ treatvar if treatvar==1 
	local t_N = r(N) //count how many treatment observations we have
	summ treatvar if treatvar==0 
	local c_N = r(N) //count how many control observations we have

	summ treatvar 
	local all_N= r(N)
	
	
		di _n "*********************** Endline 3  ************************" _n
		di _n "Total : `all_N'"  _n			 
		di _n "Total control : `c_N'"  _n	
		di _n "Total treatment : `t_N'"  _n	
	
	gen miss = 0		
	local i=0
	set seed 412024
	gen x=runiform() // to break Lee bounds ties

	eststo clear
	foreach v in `vars' { // the local vars has the outcome variables of interest

		gen TLO_`v' = 0		// obsns to trim for lower bound
		gen TUP_`v' = 0		// obsns to trim for upper bound
		gen TABS_`v' = 0	// obsns to trim for lower bound in absolute value terms

		* final total obs by treatment and control
		local ft_N = `t_N'		
		local fc_N = `c_N'		

		
		*Leebounds
		
		* Confirm if there is a variable in baseline to control for
		local ldv`v'= substr("`v'",2,.)		
		
		
		cap confirm  variable `ldv`v'', exact
		if !_rc {
			#d;
			reghdfe `v' `ldv`v'' treatvar district1 district2 district3 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}
		else {
			#d;
			reghdfe `v'  treatvar district1 district2 district3 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		}

	
		local posneg = sign(_b[treatvar])	
		replace miss = (`v'== .)		// This is so when sorting data below and using _n, don't have to worry if Stata puts missing values first or last
		
		summ `v' if treatvar==1 
		local t_n = r(N)
		local t_rate = `t_n'/`ft_N'		// retention rate for treatment group
		
		summ `v' if treatvar==0 
		local c_n = r(N)
		local c_rate = `c_n'/`fc_N'		// retention rate for control group

		
		local trim_rate = abs(`c_rate' - `t_rate')	// % of obsns to trim
		

		
		* Missing rate 
		local t_miss =`ft_N' - `t_n'
		local c_miss =`fc_N' - `c_n'
		
		local t_miss_rate=`t_miss'/`ft_N'
		local c_miss_rate=`c_miss'/`fc_N'
		local missrate_t_`v': di %7.3fc  `t_miss_rate'
		local missrate_c_`v': di %7.3fc `c_miss_rate'

		di _n " " _n		
		di _n "Outcome : `v'" _n	
		di _n "		Non-Missing control : `c_n' & Non-Missing  treatment : `t_n'" _n		
		di _n "	            Treatment missing rate:  `t_miss_rate'" _n	
		di _n "             Control missing rate:  `c_miss_rate'" _n			
		di _n "             Trim rate:  `trim_rate'" _n	
	
		if `c_rate' > `t_rate' {  // trim from control group
			local trim_n = round(`trim_rate'* `fc_N')	// number of obsns to trim

			*cap confirm variable `v'			
			 gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat `v' x /*-B_S`v'*/
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 	// trim low values from control group to get lower bound
			
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x
			
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 
		}

		if `c_rate' < `t_rate' {  // trim from treat group
			local trim_n = round(`trim_rate'* `ft_N')	// number of obsns to trim
			di `trim_n'
			*cap confirm variable B_S`v'			
			gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat E_S`v' -B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0	*/ // trim low values from treat group to get upper bound
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x 
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0*/
		}		

		* Lower bound in absolute value terms depends on whether coefficient is positive or negative (unlikely to be exactly 0, but if so, full sample gives lower abs value bound)
		if `posneg'==1 {
			replace TABS_`v' = TLO_`v' 	// if treatment effect is positive, lower bound in absolute value terms is actual lower bound

		}
		if `posneg'==-1 {
			replace TABS_`v' = TUP_`v' // if treatment effect is negative, lower bound in absolute value terms is actual upper bound
		}		

		di _n "*****   Full sample   *****" _n		
	
			#d;
			reghdfe `v'  treatvar district1 district2 district3 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		
		
		local cluster_`v': di %7.0fc `e(N_clust)'
		local obs_`v': di %7.0fc `e(N)'
		local treat_`v': di %7.3fc _b[treatvar]
		local se_`v': di %7.3fc _se[treatvar]		
		local t_`v' = _b[treatvar]/_se[treatvar]
		scalar p_`v' = 2*ttail(e(df_r),abs(`t_`v''))

		dis "cluster_`v' : `cluster_`v''"
		dis "obs_`v' : `obs_`v''"
		dis "treat_`v' : `treat_`v''"
		dis "se_`v' : `se_`v''"
		dis "t_`v' : `t_`v''"
		dis "p`v' :"
		dis p_`v'
		
		
		
		di _n "*****   Lower bound   *****" _n
	

			#d;
			reghdfe `v'  B_treat_l district1 district2 district3 if TLO_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
		
		
		local obs1_`v' : di %7.0fc `e(N)'
		local treat_l_`v': di %7.3fc _b[B_treat_l]
		local se_l_`v': di %7.3fc _se[B_treat_l]
		local t_l_`v' = _b[B_treat_l]/_se[B_treat_l]
		scalar p_l_`v' = 2*ttail(e(df_r),abs(`t_l_`v''))
		dis "obs_l_`v' : `obs_l_`v''"
		dis "treat_l_`v' : `treat_l_`v''"
		dis "se_l_`v' : `se_l_`v''"
		dis "t_l_`v' : `t_l_`v''"
		dis "p_l`v' :"
		dis p_l_`v'

		
		
		di _n "*****   Upper bound   *****" _n		
	
			#d;
			reghdfe `v'  B_treat_u district1 district2 district3 if TUP_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr

		
		
		local treat_u_`v': di %7.3fc _b[B_treat_u]
		local se_u_`v': di %7.3fc _se[B_treat_u]
		local t_u_`v' = _b[B_treat_u]/ _se[B_treat_u]
		scalar p_u_`v' = 2*ttail(e(df_r),abs(`t_u_`v''))
		dis p_u_`v'
		dis "obs_u_`v' : `obs_u_`v''"
		dis "treat_u_`v' : `treat_u_`v''"
		dis "se_u_`v' : `se_u_`v''"
		dis "t_u_`v' : `t_u_`v''"
		dis "p_u`v' :"
		dis p_u_`v'		
	

		di _n "*****   Bound on magnitude   *****" _n

			#d;
			reghdfe `v'  treatvar district1 district2 district3 if TABS_`v'==0 , 
			a(stratum) cluster(villageid)
			;
			#d cr
	
		
		
		if p_`v'< 0.01 {
			local treat_`v' `treat_`v''\sym{***}
		}
		else if 0.01 <= p_`v' & p_`v' < 0.05 {
			local treat_`v' `treat_`v''\sym{**}
		}
		else if 0.05 <= p_`v' & p_`v' < 0.1 {
			local treat_`v' `treat_`v''\sym{*}
		}
		else if p_`v'> 0.1 {
			local treat_`v' `treat_`v''
		}
		
		if p_l_`v'< 0.01 {
			local treat_l_`v' `treat_l_`v''\sym{***}
		}
		else if 0.01<= p_l_`v' & p_l_`v' < 0.05 {
			local treat_l_`v' `treat_l_`v''\sym{**}
		}
		else if 0.05<= p_l_`v' & p_l_`v' < 0.1 {
			local treat_l_`v' `treat_l_`v''\sym{*}
		}
		else if p_l_`v'> 0.1 {
			local treat_l_`v' `treat_l_`v''
		}
		
		if p_u_`v'< 0.01 {
			local treat_u_`v' `treat_u_`v''\sym{***}
		}
		else if 0.01<= p_u_`v' & p_u_`v' < 0.05 {
			local treat_u_`v' `treat_u_`v''\sym{**}
		}
		else if 0.05<= p_u_`v' & p_u_`v' < 0.1 {
			local treat_u_`v' `treat_u_`v''\sym{*}
		}
		else if p_u_`v'> 0.1 {
			local treat_u_`v' `treat_u_`v''
		}
	}

	local se
	foreach var in `vars'  {
		local se `se' se_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_l_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_u_`var'
	}
	
	foreach x in `se' {
		local `x'=trim(string(``x'',"%7.3f"))
	}

	local writetreatB`saveas' `varlab1'
	local writetreat_lB`saveas' `varlab2'
 	local writetreat_uB`saveas' `varlab3'
	local writeseB`saveas'
	local writese_lB`saveas'
	local writese_uB`saveas' 
	local writeobsB`saveas'
	local writeobs1B`saveas'
	local writemistB`saveas'
	local writemiscB`saveas'
	
	
	
	foreach var in `vars'  {
		local treat_`var' `treat_`var''
		local se_`var' `se_`var''
		local treat_l_`var' `treat_l_`var''
		local se_l_`var' `se_l_`var''
		local treat_u_`var' `treat_u_`var''
		local se_u_`var' `se_u_`var''
		local obs_`var' `obs_`var''
		local obs1_`var' `obs1_`var''
		local miss_t_`var' `missrate_t_`var''
		local miss_c_`var' `missrate_c_`var''
		
	local writetreatB`saveas' `writetreatB`saveas'' & `treat_`var''
	local writetreat_lB`saveas' `writetreat_lB`saveas'' & `treat_l_`var''
	local writetreat_uB`saveas' `writetreat_uB`saveas'' & `treat_u_`var''

	local writeseB`saveas' `writeseB`saveas'' & [`se_`var'']
	local writese_lB`saveas' `writese_lB`saveas'' & [`se_l_`var'']
	local writese_uB`saveas' `writese_uB`saveas'' & [`se_u_`var'']
	
	local writeobsB`saveas' `writeobsB`saveas'' & `obs_`var''
	local writeobs1B`saveas' `writeobs1B`saveas'' & `obs1_`var''
	local writemistB`saveas' `writemistB`saveas'' & `miss_t_`var''
	local writemiscB`saveas' `writemiscB`saveas'' & `miss_c_`var''

	}
	dis "`writetreat'"
	restore
			}
			


	}	
	
* Layout options
	#d ;
	local frame "{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\renewcommand{\arraystretch}{rowspace}  
		\begin{tabular}{{>{\hangindent=1em}p{first}}*{colno}{>{\centering\arraybackslash}m{colspace}}}
		\toprule";
	#d cr	

	local frame0 = subinstr("`frame'", "first", "5.5cm", .) // first column width
	local frame1 = subinstr("`frame0'", "colspace", "2.8cm", .) // column spacing 
	local frame2 = subinstr("`frame1'", "rowspace", "1", .) // row spacing
	local prehead = subinstr("`frame2'", "colno", "4", .)	// number of columns			
				
		
		*** combined table
		cap file close regtab
		file open regtab using "$tables/table_A3d.tex", write replace
		
		
		file write regtab "`prehead' \\" _n  
		* Panel A
			file write regtab "\cmidrule(lr){2-4}& Carbohydrates ASTE & Animal-sourced foods ASTE & Fruit and veg ASTE \\" _n
			file write regtab "  & (1) & (2) & (3) \\    " _n 
			file write regtab "\midrule" _n 
			file write regtab "& \multicolumn{3}{c}{\textbf{Panel A: Food Intake (Women and Children)}} \\" _n  
			file write regtab "\cmidrule(lr){2-4}& \multicolumn{3}{c}{\textbf{WCommHN vs. Control}} \\" _n		
		
			* Control
			file write regtab "\cmidrule(lr){2-4} `writetreat_lAcont' \\  " _n	
			file write regtab  " `writese_lAcont' \\  " _n
			

			file write regtab "`writetreat_uAcont' \\  " _n	
			file write regtab  "`writese_uAcont' \\  " _n		
			file write regtab "\midrule" _n 
			
			file write regtab "`treatgroup' missing rate `writemistAcont' \\ " _n	
			file write regtab "`controlgroupcont' missing rate  `writemiscAcont' \\ " _n	
			
			
			* WHN
			file write regtab "\midrule" _n 
			file write regtab "& \multicolumn{3}{c}{\textbf{WCommHN vs. WHN}} \\" _n
			file write regtab "\cmidrule(lr){2-4} `writetreat_lAwhn' \\  " _n	
			file write regtab  " `writese_lAwhn' \\  " _n
			

			file write regtab "`writetreat_uAwhn' \\  " _n	
			file write regtab  "`writese_uAwhn' \\  " _n		
			file write regtab "\midrule" _n 
			
			file write regtab "`treatgroup' missing rate `writemistAwhn' \\ " _n	
			file write regtab "`controlgroupwhn' missing rate  `writemiscAwhn' \\ " _n			
		
* Panel B
			file write regtab "\midrule" _n 
			file write regtab "& \multicolumn{3}{c}{\textbf{Panel B: Food Expenditure and Crop Allocation}} \\" _n  
			file write regtab "\cmidrule(lr){2-4}& \multicolumn{3}{c}{\textbf{WCommHN vs. Control}} \\" _n		
		
			* Control
			file write regtab "\cmidrule(lr){2-4} `writetreat_lBcont' \\  " _n	
			file write regtab  " `writese_lBcont' \\  " _n
			

			file write regtab "`writetreat_uBcont' \\  " _n	
			file write regtab  "`writese_uBcont' \\  " _n		
			file write regtab "\midrule" _n 
			
			file write regtab "`treatgroup' missing rate `writemistBcont' \\ " _n	
			file write regtab "`controlgroupcont' missing rate  `writemiscBcont' \\ " _n	
			
			
			* WHN
			file write regtab "\midrule" _n 
			file write regtab "& \multicolumn{3}{c}{\textbf{WCommHN vs. WHN}} \\" _n
			file write regtab "\cmidrule(lr){2-4} `writetreat_lBwhn' \\  " _n	
			file write regtab  " `writese_lBwhn' \\  " _n
			

			file write regtab "`writetreat_uBwhn' \\  " _n	
			file write regtab  "`writese_uBwhn' \\  " _n		
			file write regtab "\midrule" _n 
			
			file write regtab "`treatgroup' missing rate `writemistBwhn' \\ " _n	
			file write regtab "`controlgroupwhn' missing rate  `writemiscBwhn' \\ " _n					
		
	
		file write regtab "\bottomrule" _n           // table footer
		file write regtab "\end{tabular} }" _n 
		file close regtab			
			
		}	
		
*===============================================================================*			
* Table A.3e: Program impacts on child health outcomes: Lee bounds.
*===============================================================================*	

	if `table_a3e' == 1 {
		use "$analysis/child_level_mcm.dta", clear
	
	tab districtid, gen(district)
	drop district4	

	estimates clear
	eststo clear
			
	** clean up age variables
	
	cap drop birthyear birthmonth
	gen birthyear=year(birthdate)
	gen birthmonth=month(birthdate)
	
	* recode missing values in endline age based on birth month and year: 	
	gen flag_Eage=1 if inlist(Eage,999,.)
	replace Eage = Eanthro_date - birthdate if flag_Eage==1
	replace Eage = Eage*(12/365) if flag_Eage==1 
	drop flag_Eage
	replace Eage=. if Eage-age>30 & age!=. 
	replace Eage=round(Eage)
	
	* generate variable = child's age at the start of the intervention (February 2013)
	cap drop month day year february2013 age_start_t
	
	gen month=2
	gen day=1
	gen year=2013
	gen february2013 = mdy(month, day, year)
	format february2013 %td
	lab var february2013 "Start of intervention: February 2013"
	drop month day year
	gen month=11
	gen day=1
	gen year=2013
	gen november2013 = mdy(month, day, year)
	format november2013 %td
	lab var november2013 "End of intervention: November 2013"
	drop month day year
	
	gen age_start_t = february2013 - birthdate
	gen age_start_t_days = age_start_t
	lab var age_start_t_days "Age of child (in days) at the start of the intervention"	
	replace age_start_t = age_start_t*(12/365) 
	replace age_start_t = round(age_start_t) 
	lab var age_start_t "Age of child (in months) at the start of the intervention"	
	
	gen age_end_t = november2013 - birthdate
	replace age_end_t = age_end_t*(12/365) 
	replace age_end_t=round(age_end_t)
	lab var age_end_t "Age of child (in months) at the end of the intervention"	
			
	** main height-for-age result: all children aged 23 months or less at the start of the intervention

	** birth weight 
	gen Ebweight_kg = Ebirth_weight
	replace Ebweight_kg = . if Ebweight_kg>5 // trimming top 5% of values

	
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*								Lee-Bounds 										*	
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *	
{
***** Iterate over the different pairwise groups
decode treat, gen(treatstring)

/*
	1. WCommHN Vs WHN 
	2. WCommHN Vs Control

*/

global pairgroup inlist(treat,2,1) inlist(treat,2,3)

foreach pair in $pairgroup {
	
preserve	
	* Keep pair-wise analysis groups
	keep if `pair'
	
	* Generate treatment variable
	gen treatvar=(treat==2)	
		local treatgroup "WCommHN"
		
		if "`pair'" =="inlist(treat,2,3)" {
			local saveas whn
			local controlgroupwhn "WHN"
			
		}
		if "`pair'" =="inlist(treat,2,1)" {
			local saveas cont
			local controlgroupcont "Control"
			
		}	
		
	* Dependent variables 
	local vars Ewfa Elhfa Ebweight_kg

	gen B_treat_l=treatvar
	gen B_treat_u=treatvar
	
	lab var treatvar "`treatgroup'"
	lab var B_treat_l "`treatgroup' (Lower bound)"
	lab var B_treat_u "`treatgroup' (Upper bound)"

	local tablerow treatvar B_treat_l B_treat_u

	local varlab1: var lab treatvar
	local varlab2: var lab B_treat_l
	local varlab3: var lab B_treat_u

	summ treatvar if treatvar==1 
	local t_N = r(N) //count how many treatment observations we have
	summ treatvar if treatvar==0 
	local c_N = r(N) //count how many control observations we have

	summ treatvar 
	local all_N= r(N)
	
	
		di _n "*********************** Endline 3  ************************" _n
		di _n "Total : `all_N'"  _n			 
		di _n "Total control : `c_N'"  _n	
		di _n "Total treatment : `t_N'"  _n	
	
	gen miss = 0		
	local i=0
	set seed 412024
	gen x=runiform() // to break Lee bounds ties

	eststo clear
	foreach v in `vars' { // the local vars has the outcome variables of interest

		gen TLO_`v' = 0		// obsns to trim for lower bound
		gen TUP_`v' = 0		// obsns to trim for upper bound
		gen TABS_`v' = 0	// obsns to trim for lower bound in absolute value terms

		* final total obs by treatment and control
		local ft_N = `t_N'		
		local fc_N = `c_N'		

		
		*Leebounds
		if "`v'" == "Ewfa" {
			reghdfe `v' treatvar female district1 district2 district3 if age_start_t<=23, absorb(stratum Eage age_start_t) cluster(villageid)	
		}
		else if "`v'" == "Elhfa" {
			reghdfe `v' treatvar district1 district2 district3 female Eheight_how if age_start_t<=23, absorb(stratum Eage age_start_t) cluster(villageid)	
		}
		else if "`v'" == "Ebweight_kg" {
			reghdfe `v' treatvar district1 district2 district3 female Eweight_immcard if age_start_t_days<=-28 & onlyin==2, absorb(stratum age_start_t) cluster(villageid) 
		}
	
		local posneg = sign(_b[treatvar])	// Is treatment effect with untrimmed sample positive or negative?
		replace miss = (`v'== .)		// This is so when sorting data below and using _n, don't have to worry if Stata puts missing values first or last
		
		summ `v' if treatvar==1 
		local t_n = r(N)
		local t_rate = `t_n'/`ft_N'		// retention rate for treatment group
		
		summ `v' if treatvar==0 
		local c_n = r(N)
		local c_rate = `c_n'/`fc_N'		// retention rate for control group

		
		local trim_rate = abs(`c_rate' - `t_rate')	// % of obsns to trim
		

		
		* Missing rate 
		local t_miss =`ft_N' - `t_n'
		local c_miss =`fc_N' - `c_n'
		
		local t_miss_rate=`t_miss'/`ft_N'
		local c_miss_rate=`c_miss'/`fc_N'
		local missrate_t_`v': di %7.3fc  `t_miss_rate'
		local missrate_c_`v': di %7.3fc `c_miss_rate'

		di _n " " _n		
		di _n "Outcome : `v'" _n	
		di _n "		Non-Missing control : `c_n' & Non-Missing  treatment : `t_n'" _n		
		di _n "	            Treatment missing rate:  `t_miss_rate'" _n	
		di _n "             Control missing rate:  `c_miss_rate'" _n			
		di _n "             Trim rate:  `trim_rate'" _n	
	
		if `c_rate' > `t_rate' {  // trim from control group
			local trim_n = round(`trim_rate'* `fc_N')	// number of obsns to trim

			*cap confirm variable `v'			
			 gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat `v' x /*-B_S`v'*/
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 	// trim low values from control group to get lower bound
			
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x
			
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==0 
		}

		if `c_rate' < `t_rate' {  // trim from treat group
			local trim_n = round(`trim_rate'* `ft_N')	// number of obsns to trim
			di `trim_n'
			*cap confirm variable B_S`v'			
			gsort miss treatvar `v' x						// want to tag observations in either treat or control group that are non-missing and high or low values
			*else gsort miss B_treat E_S`v' -B_S`v' x
			by miss treatvar: replace TUP_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0	*/ // trim low values from treat group to get upper bound
			*cap confirm variable B_S`v'
			gsort miss treatvar -`v' x 
			*else gsort miss B_treat -E_S`v' B_S`v' x
			by miss treatvar: replace TLO_`v' = 1 if _n <= `trim_n' & miss==0 & treatvar==1 /*& !mi(E_Steam_id) & attrition_el==0*/
		}		

		* Lower bound in absolute value terms depends on whether coefficient is positive or negative (unlikely to be exactly 0, but if so, full sample gives lower abs value bound)
		if `posneg'==1 {
			replace TABS_`v' = TLO_`v' 	// if treatment effect is positive, lower bound in absolute value terms is actual lower bound

		}
		if `posneg'==-1 {
			replace TABS_`v' = TUP_`v' // if treatment effect is negative, lower bound in absolute value terms is actual upper bound
		}		

		di _n "*****   Full sample   *****" _n		
		if "`v'" == "Ewfa" {
			reghdfe `v' treatvar female district1 district2 district3 if age_start_t<=23, absorb(stratum Eage age_start_t) cluster(villageid)	
		}
		else if "`v'" == "Elhfa" {
			reghdfe `v' treatvar district1 district2 district3 female Eheight_how if age_start_t<=23, absorb(stratum Eage age_start_t) cluster(villageid)	
		}
		else if "`v'" == "Ebweight_kg" {
			reghdfe `v' treatvar district1 district2 district3 female Eweight_immcard if age_start_t_days<=-28 & onlyin==2, absorb(stratum age_start_t) cluster(villageid) 
		}
		
		local cluster_`v': di %7.0fc `e(N_clust)'
		local obs_`v': di %7.0fc `e(N)'
		local treat_`v': di %7.3fc _b[treatvar]
		local se_`v': di %7.3fc _se[treatvar]		
		local t_`v' = _b[treatvar]/_se[treatvar]
		scalar p_`v' = 2*ttail(e(df_r),abs(`t_`v''))

		dis "cluster_`v' : `cluster_`v''"
		dis "obs_`v' : `obs_`v''"
		dis "treat_`v' : `treat_`v''"
		dis "se_`v' : `se_`v''"
		dis "t_`v' : `t_`v''"
		dis "p`v' :"
		dis p_`v'
		
		
		
		di _n "*****   Lower bound   *****" _n
				if "`v'" == "Ewfa" {
					reghdfe `v' B_treat_l female district1 district2 district3 if age_start_t<=23 & TLO_`v'==0, absorb(stratum Eage age_start_t) cluster(villageid)	
				}
				else if "`v'" == "Elhfa" {
					reghdfe `v' B_treat_l district1 district2 district3 female Eheight_how if age_start_t<=23 & TLO_`v'==0, absorb(stratum Eage age_start_t) cluster(villageid)	
				}
				else if "`v'" == "Ebweight_kg" {
					reghdfe `v' B_treat_l district1 district2 district3 female Eweight_immcard if age_start_t_days<=-28 & onlyin==2 & TLO_`v'==0, absorb(stratum age_start_t) cluster(villageid) 
				}		
		

		
		local obs1_`v' : di %7.0fc `e(N)'
		local treat_l_`v': di %7.3fc _b[B_treat_l]
		local se_l_`v': di %7.3fc _se[B_treat_l]
		local t_l_`v' = _b[B_treat_l]/_se[B_treat_l]
		scalar p_l_`v' = 2*ttail(e(df_r),abs(`t_l_`v''))
		dis "obs_l_`v' : `obs_l_`v''"
		dis "treat_l_`v' : `treat_l_`v''"
		dis "se_l_`v' : `se_l_`v''"
		dis "t_l_`v' : `t_l_`v''"
		dis "p_l`v' :"
		dis p_l_`v'

		
		
		di _n "*****   Upper bound   *****" _n	
				if "`v'" == "Ewfa" {
					reghdfe `v' B_treat_u female district1 district2 district3 if age_start_t<=23 & TUP_`v'==0, absorb(stratum Eage age_start_t) cluster(villageid)	
				}
				else if "`v'" == "Elhfa" {
					reghdfe `v' B_treat_u district1 district2 district3 female Eheight_how if age_start_t<=23 & TUP_`v'==0, absorb(stratum Eage age_start_t) cluster(villageid)	
				}
				else if "`v'" == "Ebweight_kg" {
					reghdfe `v' B_treat_u district1 district2 district3 female Eweight_immcard if age_start_t_days<=-28 & onlyin==2 & TUP_`v'==0, absorb(stratum age_start_t) cluster(villageid) 
				}			
		
		
		local treat_u_`v': di %7.3fc _b[B_treat_u]
		local se_u_`v': di %7.3fc _se[B_treat_u]
		local t_u_`v' = _b[B_treat_u]/ _se[B_treat_u]
		scalar p_u_`v' = 2*ttail(e(df_r),abs(`t_u_`v''))
		dis p_u_`v'
		dis "obs_u_`v' : `obs_u_`v''"
		dis "treat_u_`v' : `treat_u_`v''"
		dis "se_u_`v' : `se_u_`v''"
		dis "t_u_`v' : `t_u_`v''"
		dis "p_u`v' :"
		dis p_u_`v'		
	

		di _n "*****   Bound on magnitude   *****" _n
				if "`v'" == "Ewfa" {
					reghdfe `v' treatvar female district1 district2 district3 if age_start_t<=23 & TABS_`v'==0, absorb(stratum Eage age_start_t) cluster(villageid)	
				}
				else if "`v'" == "Elhfa" {
					reghdfe `v' treatvar district1 district2 district3 female Eheight_how if age_start_t<=23 & TABS_`v'==0, absorb(stratum Eage age_start_t) cluster(villageid)	
				}
				else if "`v'" == "Ebweight_kg" {
					reghdfe `v' treatvar district1 district2 district3 female Eweight_immcard if age_start_t_days<=-28 & onlyin==2 & TABS_`v'==0, absorb(stratum age_start_t) cluster(villageid) 
				}			
	
		
		if p_`v'< 0.01 {
			local treat_`v' `treat_`v''\sym{***}
		}
		else if 0.01 <= p_`v' & p_`v' < 0.05 {
			local treat_`v' `treat_`v''\sym{**}
		}
		else if 0.05 <= p_`v' & p_`v' < 0.1 {
			local treat_`v' `treat_`v''\sym{*}
		}
		else if p_`v'> 0.1 {
			local treat_`v' `treat_`v''
		}
		
		if p_l_`v'< 0.01 {
			local treat_l_`v' `treat_l_`v''\sym{***}
		}
		else if 0.01<= p_l_`v' & p_l_`v' < 0.05 {
			local treat_l_`v' `treat_l_`v''\sym{**}
		}
		else if 0.05<= p_l_`v' & p_l_`v' < 0.1 {
			local treat_l_`v' `treat_l_`v''\sym{*}
		}
		else if p_l_`v'> 0.1 {
			local treat_l_`v' `treat_l_`v''
		}
		
		if p_u_`v'< 0.01 {
			local treat_u_`v' `treat_u_`v''\sym{***}
		}
		else if 0.01<= p_u_`v' & p_u_`v' < 0.05 {
			local treat_u_`v' `treat_u_`v''\sym{**}
		}
		else if 0.05<= p_u_`v' & p_u_`v' < 0.1 {
			local treat_u_`v' `treat_u_`v''\sym{*}
		}
		else if p_u_`v'> 0.1 {
			local treat_u_`v' `treat_u_`v''
		}
	}

	local se
	foreach var in `vars'  {
		local se `se' se_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_l_`var'
	}
	
	foreach var in `vars'  {
		local se `se' se_u_`var'
	}
	
	foreach x in `se' {
		local `x'=trim(string(``x'',"%7.3f"))
	}


	* header and no. of columns
	eststo clear
	local header
	local n_col =0
	foreach var in `vars'   {

		local varlab: variable label `var'
		local header "`header' & `varlab'" // column headers with variables labels 
		
		local ++n_col // number of columns		
		
	}


	local writetreat`saveas' `varlab1'
	local writetreat_l`saveas' `varlab2'
 	local writetreat_u`saveas' `varlab3'
	local writese`saveas'
	local writese_l`saveas'
	local writese_u`saveas' 
	local writeobs`saveas'
	local writeobs1`saveas'
	local writemist`saveas'
	local writemisc`saveas'
	
	
	
	foreach var in `vars'  {
		local treat_`var' `treat_`var''
		local se_`var' `se_`var''
		local treat_l_`var' `treat_l_`var''
		local se_l_`var' `se_l_`var''
		local treat_u_`var' `treat_u_`var''
		local se_u_`var' `se_u_`var''
		local obs_`var' `obs_`var''
		local obs1_`var' `obs1_`var''
		local miss_t_`var' `missrate_t_`var''
		local miss_c_`var' `missrate_c_`var''
		
	local writetreat`saveas' `writetreat`saveas'' & `treat_`var''
	local writetreat_l`saveas' `writetreat_l`saveas'' & `treat_l_`var''
	local writetreat_u`saveas' `writetreat_u`saveas'' & `treat_u_`var''

	local writese`saveas' `writese`saveas'' & [`se_`var'']
	local writese_l`saveas' `writese_l`saveas'' & [`se_l_`var'']
	local writese_u`saveas' `writese_u`saveas'' & [`se_u_`var'']
	
	local writeobs`saveas' `writeobs`saveas'' & `obs_`var''
	local writeobs1`saveas' `writeobs1`saveas'' & `obs1_`var''
	local writemist`saveas' `writemist`saveas'' & `miss_t_`var''
	local writemisc`saveas' `writemisc`saveas'' & `miss_c_`var''

	}
	dis "`writetreat'"

	restore
		}
		


	
	
* Layout options
	#d ;
	local frame "{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}\renewcommand{\arraystretch}{rowspace}  
		\begin{tabular}{{>{\hangindent=1em}p{first}}*{colno}{>{\centering\arraybackslash}m{colspace}}}
		\toprule";
	#d cr	

	local frame0 = subinstr("`frame'", "first", "5.5cm", .) // first column width
	local frame1 = subinstr("`frame0'", "colspace", "2.4cm", .) // column spacing 
	local frame2 = subinstr("`frame1'", "rowspace", "1", .) // row spacing
	local prehead = subinstr("`frame2'", "colno", "3", .)	// number of columns		
	
		*** combined table
		cap file close regtab
		file open regtab using "$tables/table_A3e.tex", write replace
		
		
		file write regtab "`prehead' \\" _n      
		file write regtab "& Weight-for-age Z-score & Height-for-age Z-score & Birth weight (KGs) \\" _n
		file write regtab "  & (1) & (2) & (3) \\    " _n    
	
		file write regtab "\midrule" _n 
		file write regtab "& \multicolumn{3}{c}{\textbf{WCommHN vs. Control}} \\" _n
		
		
		* Control
		file write regtab "\cmidrule(lr){2-4} `writetreat_lcont' \\  " _n	
		file write regtab  " `writese_lcont' \\  " _n
		

		file write regtab "`writetreat_ucont' \\  " _n	
		file write regtab  "`writese_ucont' \\  " _n		
		file write regtab "\midrule" _n 
		
		file write regtab "`treatgroup' missing rate `writemistcont' \\ " _n	
		file write regtab "`controlgroupcont' missing rate  `writemisccont' \\ " _n	
		
		
		* WHN
		file write regtab "\midrule" _n 
		file write regtab "& \multicolumn{3}{c}{\textbf{WCommHN vs. WHN}} \\" _n
		
		file write regtab "\cmidrule(lr){2-4} `writetreat_lwhn' \\  " _n	
		file write regtab  " `writese_lwhn' \\  " _n
		

		file write regtab "`writetreat_uwhn' \\  " _n	
		file write regtab  "`writese_uwhn' \\  " _n		

		file write regtab "\midrule" _n 
		
		file write regtab "`treatgroup' missing rate  `writemistwhn' \\ " _n	
		file write regtab "`controlgroupwhn' missing rate  `writemiscwhn' \\ " _n			
		
	
	
	
	
		file write regtab "\bottomrule" _n           // table footer
		file write regtab "\end{tabular} }" _n 
		file close regtab	
	
		
		
	}

}


*===============================================================================*			
* Table A.4a: Men's perceptions of changes to spousal relationships and communication (cf. Table 1, col. (1)-(3), and Table 2, col. (1)-(5)).
*===============================================================================*		

	if `table_a4a' == 1{

	eststo clear
	
	use "$analysis/womens_mens_mcm.dta", clear
	
	tab districtid, gen(district)
	drop district4 
	
	eststo clear
	estimates clear
	
	lab var wemp "WCommHN"
	
	*** (1) RELATIONSHIP IMPROVEMENTS
	
	forval i=1/6 {
		replace Em_rel_improve`i'=0 if Em_rel_year_imp==0
	}
	
	* Generate standardized variables
	foreach var of varlist Em_rel_improve1-Em_rel_improve6 {
		cap drop A`var'
		sum `var' if control==1
		gen A`var'=(`var'-`r(mean)')/`r(sd)'
	}
	
	* ASTE
	cap drop Em_rel_improve_aste
	egen Em_rel_improve_aste = rowmean(AEm_rel_improve*)
	
	*** (2) + (3) WOMAN PART OF DECISION-MAKING + JOINT DECISION-MAKING

	*** Recoding Household Variables
	** Household Decisions
	local HDM m_wmoney m_daily m_chealth m_cfeed 
	local EHDM Em_wmoney Em_daily Em_chealth Em_cfeed
	
	foreach var in `EHDM' {
		replace `var'_bi = `var'_who
		recode `var'_bi (3 = 1) (2 4 5 = 0) (6 99=.)
		gen `var'_joint=`var'_who==3
		replace `var'_joint=. if inlist(`var'_who,6,99)
		replace `var'_joint=. if `var'_bi==.
	}	
	
	foreach var in `HDM' {
		replace `var'_bi = `var'_who
		recode `var'_bi (2 3 = 1) (1 4 5 = 0) (6 99=.)
		gen `var'_joint=`var'_who==3
		replace `var'_joint=. if inlist(`var'_who,6,99)
		replace `var'_joint=. if `var'_bi==.
	}		
	
	*** Men 
	** Household Decisions 
	local astevarm2  m_wmoney_bi m_daily_bi m_chealth_bi m_cfeed_bi 
	local Eastevarm2 Em_wmoney_bi Em_daily_bi Em_chealth_bi Em_cfeed_bi
	local astevarm_joint m_wmoney_joint m_daily_joint m_chealth_joint m_cfeed_joint 
	local Eastevarm_joint Em_wmoney_joint Em_daily_joint Em_chealth_joint Em_cfeed_joint 
	
	*** ASTE, men's reports
	
	cap drop a_w_*_bi a_Ew_*_bi
	cap drop a_m_*_bi a_Em_*_bi
	
	* Generate standardized variables
	foreach var in `astevarm2' `astevarm_joint' {
		cap drop a_`var'
		qui sum `var' if control == 1
		gen a_`var'=(`var'-`r(mean)')/`r(sd)'
		cap drop a_E`var'
		qui sum E`var' if control == 1
		gen a_E`var'=(E`var'-`r(mean)')/`r(sd)'
	}
	
	foreach y in m {
		foreach x in bi joint {
			egen aste_`y'_`x' = rowmean(a_`y'_*_`x')
			egen Easte_`y'_`x' = rowmean(a_E`y'_*_`x')
		}
	}
	
	* Normalize all ASTEs so that SD=1
	local astelist m_rel_improve_aste aste_m_bi aste_m_joint
	foreach var in `astelist' {
		cap confirm variable `var'
		if !_rc {
			sum `var' if control==1
			replace `var'=(`var'-`r(mean)')/`r(sd)'		
		}
		sum E`var' if control==1
		replace E`var'=(E`var'-`r(mean)')/`r(sd)'		
	}
	
	******** REGRESSIONS
	
	estimates clear
	
	local covars wemp whn mhn
	local controls district? 

	foreach y in m_rel_improve_aste aste_m_bi aste_m_joint {
		cap confirm variable `y'
		if !_rc {
			eststo est`y': reghdfe E`y' `y' wemp whn mhn `controls', a(stratum) cluster(villageid)
		}
		else eststo est`y': reghdfe E`y' wemp whn mhn `controls', a(stratum) cluster(villageid) 
		sum E`y' if control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`y'
		test whn=wemp
			estadd scalar pval1 = r(p): est`y'
		test wemp=mhn
			estadd scalar pval2 = r(p): est`y'
		test whn=mhn
			estadd scalar pval3 = r(p): est`y'
	} 
	
	
	*** COLUMNS (4)-(8): DISCUSSION VARIABLES, MEN'S REPORTS
	
	recode m_fp_talk (98=.)
	
	foreach y in m_fp_talk Em_fp_talk {
		gen `y'_yno = 0 if `y' == 1
		replace `y'_yno = 1 if inlist(`y',2,3)
	}
	
	gen Em_talk_hiv = (Em_talked_hiv == 1) if !mi(Em_talked_hiv)

	* Generate standardized variables
	local varlist m_husb_sugg_food_vo m_discuss_spouse_vo m_husb_sugg_hc_vo
	
	foreach var in `varlist' {
		sum E`var' if control == 1
		gen EE`var'=(E`var'-`r(mean)')/`r(sd)'
	}
	
	egen EMhusb_HnN_index=rowmean(EEm_husb_sugg_food_vo EEm_discuss_spouse_vo EEm_husb_sugg_hc_vo)
		
	* Overall ASTE 
	local varlist m_fp_talk_yno m_talk_hiv m_plan_hhexpend6
	
	foreach var in `varlist' {
		cap confirm variable `var'
			if !_rc {
				sum `var' if control == 1
				gen B`var'=(`var'-`r(mean)')/`r(sd)'
			}
			sum E`var' if control == 1
			gen EE`var'=(E`var'-`r(mean)')/`r(sd)'
	}
		
	egen Em_marcomm_aste = rowmean(EEm_fp_talk_yno EEm_talk_hiv EEm_husb_sugg_food_vo EEm_discuss_spouse_vo EEm_husb_sugg_hc_vo EEm_plan_hhexpend6)
	egen m_marcomm_aste = rowmean(Bm_fp_talk_yno Bm_plan_hhexpend6)
	
	* Normalize ASTEs so that SD=1
	foreach var in EMhusb_HnN_index Em_marcomm_aste m_marcomm_aste {
		sum `var' if control==1
		replace `var'=(`var'-`r(mean)')/`r(sd)'				
	}
	
	local controls district? 
	
	foreach var in m_fp_talk_yno m_talk_hiv Mhusb_HnN_index m_plan_hhexpend6 m_marcomm_aste {	
		cap confirm variable `var'
		if !_rc {
			eststo est`var': areg E`var' `var' wemp whn mhn `controls', a(stratum) cluster(villageid)
		}
		else eststo est`var': areg E`var' wemp whn mhn `controls', a(stratum) cluster(villageid)
			sum E`var' if control==1 
				local num: display %4.3f `r(mean)'
				estadd local mean "`num'": est`var'
				local num: display %4.3f `r(sd)'
				estadd local sd "(`num')": est`var'
				test whn=wemp
					estadd scalar pval1=r(p): est`var'
				test wemp=mhn
					estadd scalar pval2=r(p): est`var'
				test whn=mhn
					estadd scalar pval3=r(p): est`var'
	}		
	
	#delimit ;
	esttab using "$tables/table_A4a.tex", 
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs style(tex) 
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none)
		order(wemp whn mhn) prehead("{ \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
		\begin{tabular}{l*{8}{c}} \toprule \toprule
		&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)}&\multicolumn{1}{c}{(7)}&\multicolumn{1}{c}{(8)}\\ 
		\midrule
		&\multicolumn{1}{c}{Relationship} &\multicolumn{1}{c}{Wife part of} &\multicolumn{1}{c}{Couple makes} &\multicolumn{1}{c}{Discusses} &\multicolumn{1}{c}{Discusses} &\multicolumn{1}{c}{Health \& Nutrition} &\multicolumn{1}{c}{Discusses HH} &\multicolumn{1}{c}{Overall} \\
		&\multicolumn{1}{c}{improved} &\multicolumn{1}{c}{household} &\multicolumn{1}{c}{decisions} &\multicolumn{1}{c}{FP with} &\multicolumn{1}{c}{HIV with} &\multicolumn{1}{c}{discussion}&\multicolumn{1}{c}{finance with}&\multicolumn{1}{c}{discussion} \\
		&\multicolumn{1}{c}{} &\multicolumn{1}{c}{decisions} &\multicolumn{1}{c}{together} &\multicolumn{1}{c}{spouse} &\multicolumn{1}{c}{spouse} &\multicolumn{1}{c}{ASTE} &\multicolumn{1}{c}{spouse} & \multicolumn{1}{c}{ASTE} \\
		&\multicolumn{1}{c}{ASTE} &\multicolumn{1}{c}{ASTE} &\multicolumn{1}{c}{ASTE} &\multicolumn{1}{c}{} &\multicolumn{1}{c}{} &\multicolumn{1}{c}{} &\multicolumn{1}{c}{} & \multicolumn{1}{c}{} \\
		\midrule") 
		postfoot("\bottomrule \bottomrule \end{tabular} }") posthead(" ")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean of outcome" " " "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f  %20s %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr		
	}
		
*===============================================================================*			
* Table A.4b: Program impacts on shared decision-making when both spouses' reports are concordant.
*===============================================================================*	

	if `table_a4b' == 1 {	
		
		
		use "$analysis/womens_mens_mcm.dta", clear
		
		tab districtid, gen(district)
		drop district4 
			
		*** Recoding Household Variables
		** Household Decision
		local HDW w_wmoney w_daily w_chealth w_cfeed   
		local EHDW Ew_wmoney Ew_daily Ew_chealth Ew_cfeed   
		local HDM m_wmoney m_daily m_chealth m_cfeed 
		local EHDM Em_wmoney Em_daily Em_chealth Em_cfeed
		
		foreach var in `HDW' `EHDW' `EHDM' {
			gen `var'_joint=`var'_who==3
			replace `var'_joint=. if inlist(`var'_who,6,99)
			replace `var'_bi = `var'_who
			recode `var'_bi (3 = 1) (2 4 5 = 0) (6 99=.)
			replace `var'_joint=. if `var'_bi==.
		}	
		
		foreach var in `HDM' {
			gen `var'_joint=`var'_who==3
			replace `var'_joint=. if inlist(`var'_who,6,99)
			replace `var'_bi = `var'_who
			recode `var'_bi (2 3 = 1) (1 4 5 = 0) (6 99=.)
			replace `var'_joint=. if `var'_bi==.
		}		
			
		** ASTEs of both women's and men's reports: 
		
		foreach y in daily chealth cfeed wmoney  {
			*agree that decisions are made jointly
			gen agree_E`y'_joint=1 if (Em_`y'_joint==1 & Ew_`y'_joint==1)
			replace agree_E`y'_joint=0 if (Em_`y'_joint==0 | Ew_`y'_joint==0)		
			gen agree_`y'_joint=1 if (m_`y'_joint==1 & w_`y'_joint==1)
			replace agree_`y'_joint=0 if (m_`y'_joint==0 | w_`y'_joint==0)		
			
			*agree that woman has a say
			gen agree_E`y'_wsay=1 if (Em_`y'_bi==1 & Ew_`y'_bi==1)
			replace agree_E`y'_wsay=0 if (Em_`y'_bi==0 | Ew_`y'_bi==0)		
			gen agree_`y'_wsay=1 if (m_`y'_bi==1 & w_`y'_bi==1)
			replace agree_`y'_wsay=0 if (m_`y'_bi==0 | w_`y'_bi==0)		
		}
		
		* Generate standardized variables
		foreach var of varlist agree_*_joint agree_*_wsay {
			cap drop a_`var'
			qui sum `var' if control == 1
			gen a_`var'=(`var'-`r(mean)')/`r(sd)'
		}
		
		egen aste_agree_joint = rowmean(a_agree_daily_joint a_agree_chealth_joint a_agree_cfeed_joint a_agree_wmoney_joint)
		egen Easte_agree_joint = rowmean(a_agree_Edaily_joint a_agree_Echealth_joint a_agree_Ecfeed_joint a_agree_Ewmoney_joint)
		egen aste_agree_wsay = rowmean(agree_daily_wsay agree_chealth_wsay agree_cfeed_wsay agree_wmoney_wsay)
		egen Easte_agree_wsay = rowmean(agree_Edaily_wsay agree_Echealth_wsay agree_Ecfeed_wsay agree_Ewmoney_wsay)

		* Normalize all ASTEs so that SD=1
		foreach var in aste_agree_joint aste_agree_wsay {
			cap confirm variable `var'
			if !_rc {
				sum `var' if control==1
				replace `var'=(`var'-`r(mean)')/`r(sd)'		
			}
			sum E`var' if control==1
			replace E`var'=(E`var'-`r(mean)')/`r(sd)'		
		}
		
		eststo clear
		estimates clear
		
		local controls 	district?
		local covars wemp whn mhn
		lab var wemp "WCommHN"
		
		foreach y in aste_agree_wsay aste_agree_joint {
			eststo estimation`y': areg E`y' `covars' `controls' `y', absorb(stratum) cluster(villageid)	
			sum E`y' if control==1 
			local num: display %4.3f `r(mean)'
				estadd local mean "`num'": estimation`y'
			local num: display %4.3f `r(sd)'
				estadd local sd "(`num')": estimation`y'
			test whn=wemp
				estadd scalar pval1 = r(p): estimation`y'
			test wemp=mhn
				estadd scalar pval2 = r(p): estimation`y'
			test whn=mhn
				estadd scalar pval3 = r(p): estimation`y'
		}
		
		#delimit ;
		esttab using "$tables/table_A4b.tex", 
			b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs style(tex) 
			keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none)
			order(wemp whn mhn) prehead("{ \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
			\begin{tabular}{l*{2}{c}} \toprule \toprule 
			&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}\\ 
			& \multicolumn{1}{c}{Wife has a} & \multicolumn{1}{c}{Decisions made} \\
			& \multicolumn{1}{c}{say} & \multicolumn{1}{c}{jointly} \\
			& \multicolumn{1}{c}{ASTE} & \multicolumn{1}{c}{ASTE} \\
			\midrule") 
			postfoot("\bottomrule\bottomrule \end{tabular} }")
			stats(mean sd pval1 pval2 pval3 N, 
			labels("Control mean of outcome" " " "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
			fmt(%4.3f  %20s %4.3f %4.3f %4.3f %9.0fc));
		#delimit cr	
	}
	
	
*===============================================================================*			
* Table A.5a: Components of Relationship Improvements Index (cf. Table 1, column (1)).
*===============================================================================*		
	
	if `table_a5a' == 1	{
	
	eststo clear
	
	use "$analysis/womens_mens_mcm.dta", clear
	
	tab districtid, gen(district)
	drop district4 
	
	local controls 	district? 
	local covars 	wemp whn mhn
	
	estimates clear
	
	lab var wemp "WCommHN"
	
	*** (1) RELATIONSHIP IMPROVEMENTS ***
	
	forval i = 1/6 {
		replace Ew_rel_improve`i'=0 if Ew_rel_year_imp==0
		replace Em_rel_improve`i'=0 if Em_rel_year_imp==0
	}
	
	** Women
	foreach y in Ew_rel_improve1 Ew_rel_improve2 Ew_rel_improve6 Ew_rel_improve3 Ew_rel_improve4 Ew_rel_improve5 {
		eststo estimation`y': reghdfe `y' wemp whn mhn `controls', a(stratum) cluster(villageid) 
		sum `y' if control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimation`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimation`y'
		test whn=wemp
			estadd scalar pval1 = r(p): estimation`y'
		test wemp=mhn
			estadd scalar pval2 = r(p): estimation`y'
		test whn=mhn
			estadd scalar pval3 = r(p): estimation`y'
	}

	#delimit ;
	esttab using "$tables/table_A5a.tex", 
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs style(tex) 
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none)
		order(wemp whn mhn) prehead("{ \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
		\begin{tabular}{l*{6}{c}} \toprule \toprule
		&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)}\\ 
		\midrule
		&\multicolumn{1}{c}{Husband} &\multicolumn{1}{c}{Wife listens} &\multicolumn{1}{c}{Share}&\multicolumn{1}{c}{Have} &\multicolumn{1}{c}{Husband more}&\multicolumn{1}{c}{Share}\\
		&\multicolumn{1}{c}{listens more} &\multicolumn{1}{c}{more to} &\multicolumn{1}{c}{more} &\multicolumn{1}{c}{fewer}&\multicolumn{1}{c}{involved}&\multicolumn{1}{c}{household}\\
		&\multicolumn{1}{c}{to wife} &\multicolumn{1}{c}{husband} &\multicolumn{1}{c}{information}&\multicolumn{1}{c}{arguments}&\multicolumn{1}{c}{w/ family}&\multicolumn{1}{c}{finances} \\
		\midrule") 
		postfoot("\bottomrule \bottomrule \end{tabular} }") posthead(" ")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean of outcome" " " "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f  %20s %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr	
			
	}
	
	
*===============================================================================*			
* Table A.5b: Components of Woman's Decision-making Power Index (cf. Table 1, column (2)).
*===============================================================================*		
	
	if `table_a5b' == 1	{
	use "$analysis/womens_mens_mcm.dta", clear
	
	tab districtid, gen(district)
	drop district4 
	
	estimates clear
	
	local controls 	district? 
	local covars 	wemp whn mhn
	lab var wemp "WCommHN"
	
	*** (1) RELATIONSHIP IMPROVEMENTS ***
	
	forval i = 1/6 {
		replace Ew_rel_improve`i'=0 if Ew_rel_year_imp==0
		replace Em_rel_improve`i'=0 if Em_rel_year_imp==0
	}
	
	*** Recoding Household Variables
	** Household Decision
	local HD  w_wmoney w_purch w_savespend w_wcloth w_daily w_chealth w_cfeed w_cschool w_ccloth 
	local EHD Ew_wmoney Ew_purch Ew_savespend Ew_wcloth Ew_daily Ew_chealth Ew_cfeed Ew_cschool Ew_ccloth 
	local HDW w_wmoney w_daily w_chealth w_cfeed   
	local EHDW Ew_wmoney Ew_daily Ew_chealth Ew_cfeed   
	local HDM m_wmoney m_daily m_chealth m_cfeed 
	local EHDM Em_wmoney Em_daily Em_chealth Em_cfeed
	
	foreach var in `HD' `EHD' `EHDM' {
		gen `var'_joint=`var'_who==3
		replace `var'_joint=. if inlist(`var'_who,6,99)
		replace `var'_bi = `var'_who
		recode `var'_bi (3 = 1) (2 4 5 = 0) (6 99=.)
		replace `var'_joint=. if `var'_bi==.
	}	
	
	foreach var in `HDM' {
		gen `var'_joint=`var'_who==3
		replace `var'_joint=. if inlist(`var'_who,6,99)
		replace `var'_bi = `var'_who
		recode `var'_bi (2 3 = 1) (1 4 5 = 0) (6 99=.)
		replace `var'_joint=. if `var'_bi==.
	}		
	
	** Women's reports: woman has a say in hh decisions (Table 1, col. 2, Panel A)
	* tab Ew_cschool_bi if Ew_purch_bi!=., mis
	* at endline, Ew_cschool_bi is missing for 15.5% of the sample -- all cases of "Not applicable", so must be that children don't go to school (yet, or not at all) or that there are no expenses (less likely) 
	* w_cschool_bi is missing for 23% of the sample
	
	foreach y in w_daily w_purch w_savespend w_wmoney w_chealth w_cfeed w_cschool w_wcloth w_ccloth   {
		eststo estimation`y': areg E`y'_bi `covars' `y'_bi `controls', absorb(stratum) cluster(villageid)	
		sum E`y'_bi if control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimation`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimation`y'
		test whn=wemp
			estadd scalar pval1 = r(p): estimation`y'
		test wemp=mhn
			estadd scalar pval2 = r(p): estimation`y'
		test whn=mhn
			estadd scalar pval3 = r(p): estimation`y'
	}

	#delimit ;
	esttab using "$tables/table_A5b.tex", 
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs style(tex) 
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none)
		order(wemp whn mhn) prehead("{ \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
		\begin{tabular}{l*{9}{c}} \toprule \toprule 
		&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)}&\multicolumn{1}{c}{(7)}&\multicolumn{1}{c}{(8)}&\multicolumn{1}{c}{(9)}\\ 
		\midrule
		& \multicolumn{9}{c}{\textbf{Wife has a say in:}} \\
		\cmidrule(lr){2-10} 
		& Daily & Major  & Save or & Spending & Children's & What to & Schooling & Women's & Children's \\ 
		& household & household & spend & own & health & feed the & expenses & clothing & clothing \\ 
		& needs & purchases & money & earnings & costs & children &  &  & \\ 
		\midrule") 
		postfoot("\bottomrule \bottomrule \end{tabular} }") posthead(" ")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean of outcome" " " "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f  %20s %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr		
		
	}

*===============================================================================*			
* Table A.5c: Components of Joint Decision-making Index (cf. Table 1, column (3)).
*===============================================================================*		
	
	if `table_a5c' == 1 {
	use "$analysis/womens_mens_mcm.dta", clear
	
	tab districtid, gen(district)
	drop district4 
	
	local controls 	district? 
	local covars 	wemp whn mhn
	estimates clear
	
	lab var wemp "WCommHN"
	
	*** (1) RELATIONSHIP IMPROVEMENTS ***
	
	forval i = 1/6 {
		replace Ew_rel_improve`i'=0 if Ew_rel_year_imp==0
		replace Em_rel_improve`i'=0 if Em_rel_year_imp==0
	}
	
	
	*** Recoding Household Variables
	** Household Decision
	local HD  w_wmoney w_purch w_savespend w_wcloth w_daily w_chealth w_cfeed w_cschool w_ccloth 
	local EHD Ew_wmoney Ew_purch Ew_savespend Ew_wcloth Ew_daily Ew_chealth Ew_cfeed Ew_cschool Ew_ccloth 
	local HDW w_wmoney w_daily w_chealth w_cfeed   
	local EHDW Ew_wmoney Ew_daily Ew_chealth Ew_cfeed   
	local HDM m_wmoney m_daily m_chealth m_cfeed 
	local EHDM Em_wmoney Em_daily Em_chealth Em_cfeed
	
	foreach var in `HD' `EHD' `EHDM' {
		gen `var'_joint=`var'_who==3
		replace `var'_joint=. if inlist(`var'_who,6,99)
		replace `var'_bi = `var'_who
		recode `var'_bi (3 = 1) (2 4 5 = 0) (6 99=.)
		replace `var'_joint=. if `var'_bi==.
	}	
	
	foreach var in `HDM' {
		gen `var'_joint=`var'_who==3
		replace `var'_joint=. if inlist(`var'_who,6,99)
		replace `var'_bi = `var'_who
		recode `var'_bi (2 3 = 1) (1 4 5 = 0) (6 99=.)
		replace `var'_joint=. if `var'_bi==.
	}		
	

	
	** Women's reports: hh decisions are made jointly

	foreach y in w_daily w_purch w_savespend w_wmoney w_chealth w_cfeed w_cschool w_wcloth w_ccloth   {
		eststo estimation`y': areg E`y'_joint `covars' `y'_joint `controls', absorb(stratum) cluster(villageid)	
		sum E`y'_joint if control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimation`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimation`y'
		test whn=wemp
			estadd scalar pval1 = r(p): estimation`y'
		test wemp=mhn
			estadd scalar pval2 = r(p): estimation`y'
		test whn=mhn
			estadd scalar pval3 = r(p): estimation`y'
	}

	#delimit ;
	esttab using "$tables/table_A5c.tex", 
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs style(tex) 
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none)
		order(wemp whn mhn) prehead("{ \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
		\begin{tabular}{l*{9}{c}} \toprule \toprule 
		&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)}&\multicolumn{1}{c}{(7)}&\multicolumn{1}{c}{(8)}&\multicolumn{1}{c}{(9)}\\ 
		\midrule
		& \multicolumn{9}{c}{\textbf{Decisions made jointly by couple:}} \\
		\cmidrule(lr){2-10} 
		& Daily & Major  & Save or & Spending & Children's & What to & Schooling & Women's & Children's \\ 
		& household & household & spend & own & health & feed the & expenses & clothing & clothing \\ 
		& needs & purchases & money & earnings & costs & children &  &  & \\ 
		\midrule") 
		postfoot("\bottomrule \bottomrule \end{tabular} }") posthead(" ")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean of outcome" " " "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f  %20s %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr		
	}
	

*===============================================================================*			
* Table A.5d: Components of Husband's Violent Behavior Index (cf. Table 1, column (4)).
*===============================================================================*		
		
	if `table_a5d' == 1{
	use "$analysis/womens_mens_mcm.dta", clear
	
	eststo clear
	estimates clear
	
	tab districtid, gen(district)
	drop district4	
	
	local controls 	district? 
	local covars 	wemp whn mhn
	lab var wemp "WCommHN"	
	
	foreach var in w_humil w_threat w_insult w_beat w_push w_slap w_violent {
		cap drop `var'_no 
		gen `var'_no=1 if `var'freq==3 // no such violence from husband in past year or month
		replace `var'_no=1 if `var'==0 // never been violent in that way
		replace `var'_no=0 if inlist(`var'freq,1,2) // often or sometimes in past year or month
		
		cap drop E`var'_no 
		gen E`var'_no=1 if E`var'freq==3 // no such violence from husband in past year or month
		replace E`var'_no=1 if E`var'==0 // never been violent in that way
		replace E`var'_no=0 if inlist(E`var'freq,1,2) // often or sometimes in past year or month
	}
	
	foreach y in w_humil_no w_threat_no w_insult_no w_beat_no w_push_no w_slap_no w_violent_no {
		eststo estimation`y': areg E`y' `covars' `controls' `y', absorb(stratum) cluster(villageid)	
		sum E`y' if control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimation`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimation`y'
		test whn=wemp
			estadd scalar pval1 = r(p): estimation`y'
		test wemp=mhn
			estadd scalar pval2 = r(p): estimation`y'
		test whn=mhn
			estadd scalar pval3 = r(p): estimation`y'
	}

	#delimit ;
	esttab using "$tables/table_A5d.tex", 
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs style(tex) 
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none)
		order(wemp whn mhn) prehead("{ \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
		\begin{tabular}{l*{7}{c}} \toprule \toprule 
		&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)}&\multicolumn{1}{c}{(7)}\\ 
		\midrule
		& \multicolumn{7}{c}{\textbf{Husband less likely to exert violent behavior:}} \\
		\cmidrule(lr){2-8} 
		&Humiliate &Threaten &Insult &Beat &Push &Slap & Other\\
		\midrule") 
		postfoot("\bottomrule \bottomrule \end{tabular} }") posthead(" ")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean of outcome" " " "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f  %20s %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr	
			
	}

	
*===============================================================================*			
* Table A.6a: Components of Health and Nutrition Discussion Index (cf. Table 2, column (3)).
*===============================================================================*		
	
	if `table_a6a' == 1	{
			use "$analysis/womens_mens_mcm.dta", clear
	
	eststo clear
	estimates clear
		
	tab districtid, gen(district)
	drop district4	
	
	local control district1 district2 district3 
	local covars 	wemp whn mhn
	lab var wemp "WCommHN"	
	
	foreach y in w_discuss_spouse_vo w_husb_sugg_food_st w_husb_sugg_hc_vo {				
		eststo est`y': areg E`y' `control' `covars', a(stratum) cluster(villageid)
			sum E`y' if control==1 
			local num: display %4.3f `r(mean)'
				estadd local mean "`num'": est`y'
			local num: display %4.3f `r(sd)'
				estadd local sd "(`num')": est`y'
			test whn=wemp
				estadd scalar pval1=r(p): est`y'
			test wemp=mhn
				estadd scalar pval2=r(p): est`y'
			test whn=mhn
				estadd scalar pval3=r(p): est`y'
	}	
	
	
	#delimit ;
	esttab using "$tables/table_A6a.tex", 
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs style(tex) 
		keep(wemp whn mhn) collabels(, none) mlabels(,none) eqlabel(,none)
		order(wemp whn mhn)
		prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
		\begin{tabular}{@{\extracolsep{-6pt}}l*{3}{>{\centering\arraybackslash}m{3.0cm}}}
		\toprule\toprule           
		&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}\\ 
		\midrule
		&\multicolumn{1}{c}{Spouses}&\multicolumn{1}{c}{Husband}&\multicolumn{1}{c}{Husband}\\       
		&\multicolumn{1}{c}{discuss family's}&\multicolumn{1}{c}{makes suggestions}&\multicolumn{1}{c}{makes suggestions}\\           
		&\multicolumn{1}{c}{health \& nutrition}&\multicolumn{1}{c}{about types of}&\multicolumn{1}{c}{about children's}\\           
		&\multicolumn{1}{c}{improvement}&\multicolumn{1}{c}{food to eat}&\multicolumn{1}{c}{health care}\\                 
        \midrule") 
		posthead(" ")	
		postfoot("\bottomrule \bottomrule \end{tabular} }")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean of outcome" " " "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f  %20s %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr		

		
		}
	
	
*===============================================================================*			
* Table A.6b: Health Knowledge Index: Components (cf. Table 2, column (6))
*===============================================================================*	
	
	if 	`table_a6b' == 1 {
			use "$analysis/womens_mens_mcm.dta", clear
	
	eststo clear
	estimates clear
			
	tab districtid, gen(district)
	drop district4	

	local control district? 
	local covars  wemp whn mhn
	lab var wemp "WCommHN"

	
	// WOMEN
	
	** Women's reports, Part 1: 
				#delimit ;
	local health_knowledge_vars_part1
w_cstrum_impt_why_bi
w_ageliquid_6
w_agefood_6
w_grow_lackdiet_vm
w_bfeed24
w_timedeworm_5
w_child_worms_bi
w_child_vomit_bi ;
				#delimit cr
				
	foreach y in `health_knowledge_vars_part1'{
		cap confirm variable `y'
		if !_rc {
			cap drop knowledge
			gen knowledge = `y'
			eststo est`y': areg E`y' knowledge `covars' `control', absorb(stratum) cluster(villageid)	
		}
		else eststo est`y': areg E`y' `covars' `control' , absorb(stratum) cluster(villageid)	
		sum E`y' if control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`y'
		test whn=wemp
			estadd scalar pval1=r(p): est`y'
		test wemp=mhn
			estadd scalar pval2=r(p): est`y'
		test whn=mhn
			estadd scalar pval3=r(p): est`y'
	} 
	
			#delimit ;
	esttab using "$tables/table_A6b_f.tex",
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs  
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none) order(wemp whn mhn) 
		prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
		\begin{tabular}{@{\extracolsep{-6pt}}l*{8}{>{\centering\arraybackslash}m{2.0cm}}}
		\toprule\toprule
		&\multicolumn{8}{c}{\textbf{Panel A: Female respondents}} \\
		\cmidrule(lr){2-9}
		& Colostrum important for immunity/growth & Introduce other liquid than breast milk at 6mo. & Introduce other food at 6mo. & Lack of balanced diet impacts child growth & Babies should be breastfed for 24 months 
		& Children should be dewormed every 6 months & Worms can contribute to anemia and malaria & Give ORS if child is vomitting or has diarrhea  \\")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean" " "  "p: WCommHN=WHN" "p: WCommHN=WHN" "p: WCommHN=WHN" "Observations") 
		fmt(%4.3f  %20s  %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr	
	
	eststo clear
	estimates clear
	
	** Women's reports, Part 2: 
	
			#delimit ;
	local health_knowledge_vars_part2
w_boys_eatmore_bi
w_safe_primhc_bi
w_menprot_bi
w_anem_foods_bi 
w_boil_1min_bi
w_condom_times_bi
w_hygint_bi
w_food_plate_bi ;
			#delimit cr	
		
	foreach y in `health_knowledge_vars_part2' {
		cap confirm variable `y'
		if !_rc {
			cap drop knowledge
			gen knowledge = `y'
			eststo est`y': areg E`y' knowledge `covars' `control' , absorb(stratum) cluster(villageid)	
		}
		else eststo est`y': areg E`y' `covars' `control' , absorb(stratum) cluster(villageid)	
		sum E`y' if control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`y'
		test whn=wemp
			estadd scalar pval1=r(p): est`y'
		test wemp=mhn
			estadd scalar pval2=r(p): est`y'
		test whn=mhn
			estadd scalar pval3=r(p): est`y'
	} 
		
			#delimit ;
	esttab using "$tables/table_A6b_f.tex",
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets append gaps label booktabs  
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none) order(wemp whn mhn) 
		prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
		\begin{tabular}{@{\extracolsep{-6pt}}l*{8}{>{\centering\arraybackslash}m{2.0cm}}}
		& Boys and girls should both eat as much meat & Low-risk pregnant women should give birth in hospital & Animal protein is not less important for women & Best foods to eat if you have anemia & Water must be boiled for several minutes to make it clean & Male condoms can only be used once & Poor hygiene can impact child's intelligence & Correctly identify healthy food plate for adult \\
		\midrule") 
		postfoot("\bottomrule \bottomrule \end{tabular} }") posthead(" ")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean" " "  "p: WCommHN=WHN" "p: WCommHN=WHN" "p: WCommHN=WHN" "Observations") 
		fmt(%4.3f  %20s  %4.3f %4.3f %4.3f %9.0fc));
			#delimit cr

		// MEN
		
	eststo clear
	estimates clear

	** Men's reports, Part 1: 

	local health_knowledge_vars_part1 m_cstrum_impt_why_bi m_ageliquid_6 m_agefood_6 m_grow_lackdiet_vm m_bfeed24 m_timedeworm_5 m_child_worms_bi m_child_vomit_bi
	
	foreach y in `health_knowledge_vars_part1'{
		cap confirm variable `y'
		if !_rc {
			cap drop knowledge
			gen knowledge = `y'
			eststo est`y': areg E`y' knowledge `covars' `control' , absorb(stratum) cluster(villageid)	
		}
		else eststo est`y': areg E`y' `covars' `control' , absorb(stratum) cluster(villageid)	
		sum E`y' if control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`y'
		test whn=wemp
			estadd scalar pval1=r(p): est`y'
		test wemp=mhn
			estadd scalar pval2=r(p): est`y'
		test whn=mhn
			estadd scalar pval3=r(p): est`y'
	} 
	
	#delimit ;
	esttab using "$tables/table_A6b_m.tex",
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs  
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none) order(wemp whn mhn) 
		prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
		\begin{tabular}{@{\extracolsep{-6pt}}l*{8}{>{\centering\arraybackslash}m{2.0cm}}}
		\toprule\toprule
		&\multicolumn{8}{c}{\textbf{Panel B: Male respondents}} \\
		\cmidrule(lr){2-9}
		& Colostrum important for immunity/growth & Introduce other liquid than breast milk at 6mo. & Introduce other food at 6mo. & Lack of balanced diet impacts child growth & Babies should be breastfed for 24 months 
		& Children should be dewormed every 6 months & Worms can contribute to anemia and malaria & Give ORS if child is vomitting or has diarrhea  \\
		\midrule") 
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean" " "  "p: WCommHN=WHN" "p: WCommHN=WHN" "p: WCommHN=WHN" "Observations") 
		fmt(%4.3f  %20s  %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr	
	
	eststo clear
	estimates clear
	
	** Men's reports, Part 2: 
	
			#delimit ;
	local health_knowledge_vars_part2
m_boys_eatmore_bi
m_safe_primhc_bi
m_menprot_bi
m_anem_foods_bi 
m_boil_1min_bi
m_condom_times_bi
m_hygint_bi
m_food_plate_bi ;
			#delimit cr	
		
	foreach y in `health_knowledge_vars_part2' {
		cap confirm variable `y'
		if !_rc {
			cap drop knowledge
			gen knowledge = `y'
			eststo est`y': areg E`y' knowledge `covars' `control' , absorb(stratum) cluster(villageid)	
		}
		else eststo est`y': areg E`y' `covars' `control' , absorb(stratum) cluster(villageid)	
		sum E`y' if control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`y'
		test whn=wemp
			estadd scalar pval1=r(p): est`y'
		test wemp=mhn
			estadd scalar pval2=r(p): est`y'
		test whn=mhn
			estadd scalar pval3=r(p): est`y'
	} 
		
			#delimit ;
	esttab using "$tables/table_A6b_m.tex",
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets append gaps label booktabs  
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none) order(wemp whn mhn) 
		prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
		\begin{tabular}{@{\extracolsep{-6pt}}l*{8}{>{\centering\arraybackslash}m{2.0cm}}}
		& Boys and girls should both eat as much meat & Low-risk pregnant women should give birth in hospital & Animal protein is not less important for women & Best foods to eat if you have anemia & Water must be boiled for several minutes to make it clean & Male condoms can only be used once & Poor hygiene can impact child's intelligence & Correctly identify healthy food plate for adult \\
		\midrule") 
		postfoot("\bottomrule \bottomrule \end{tabular} }") posthead(" ")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean" " "  "p: WCommHN=WHN" "p: WCommHN=WHN" "p: WCommHN=WHN" "Observations") 
		fmt(%4.3f  %20s  %4.3f %4.3f %4.3f %9.0fc));
			#delimit cr
	
	}
	
	
*=======================================================================================================*			
* Table A.7: Program impacts on health behaviors: newborn health, maternal health, sanitary practices.
*=======================================================================================================*		

	if `table_a7' == 1 {
	
	use "$analysis/womens_mens_mcm.dta", clear
	
	tab districtid, gen(district)
	drop district4	
	
	eststo clear		
	estimates clear
	
	** Maternal health variables (only for mothers who are currently pregnant or have been pregnant in the past 2 years before endline)	
		// 3,860 endline pregnancies in past 2 years, including 780 current pregnancies

	* antenatal care
	
	cap drop Ew_latestpreg_ac2 w_latestpreg_ac2
	
	gen Ew_latestpreg_ac2 = Ew_lastpreg_ac if Ew_pregpast2 == 1 
		replace Ew_latestpreg_ac2 = Ew_preg_ac if Ew_pregnow == 1 & Ew_preg_ac!=. 
		
	gen w_latestpreg_ac2 = w_preg_ac2 if w_pregpast2 == 1
		replace w_latestpreg_ac2 = w_preg_ac if w_pregnow == 1 & w_preg_ac!=. 
	
	* did woman eat more of certain foods during last pregnancy
	
	cap drop Ew_latestpreg_foods2 w_latestpreg_foods2	
	
	gen Ew_latestpreg_foods2 = Ew_lastpreg_foods if Ew_pregpast2 == 1 
		replace Ew_latestpreg_foods2 = Ew_preg_foods if Ew_pregnow == 1 & Ew_preg_foods!=. 
	
	gen w_latestpreg_foods2 = w_lastpreg_foods if w_pregpast2==1
		replace w_latestpreg_foods2 = w_preg_foods if w_pregnow==1 & w_preg_foods!=. 
				
	// PANEL A part 1: Newborn health: adherence to guidelines
	
	estimates clear
	
	local controls district? 
	local covars wemp whn mhn
	lab var wemp "WCommHN"
	
	foreach y in w_first_check_weeks_bi w_breastfeed w_breastfed_weeks_bi w_colostrum w_bfeed_atemore w_othliq_1week w_othliq_3mo   { 
		eststo est`y': areg E`y' `y' `covars' `controls', absorb(stratum) cluster(villageid)		
		sum E`y' if control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`y'
		test whn=wemp
			estadd scalar pval1=r(p): est`y'
		test wemp=mhn
			estadd scalar pval2=r(p): est`y'
		test whn=mhn
			estadd scalar pval3=r(p): est`y'	
	}
	
	#delimit ;
	esttab using "$tables/table_A7.tex", 
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs  
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none) order(wemp whn mhn) 
		prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
		\begin{tabular}{@{\extracolsep{-6pt}}l*{7}{>{\centering\arraybackslash}m{2.0cm}}}
		\toprule\toprule
		&\multicolumn{7}{c}{\textbf{Newborn health}} \\
		\cmidrule(lr){2-8}
		& First health check timing $<$ median & Ever breastfed & Time after birth tried breastfeeding $<$ median & Fed colostrum at birth & Woman ate more when breastfeeding & No other liquids in first week & No other liquids in first 3 months \\")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean of outcome" " "  "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f  %20s  %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr	
	
	eststo clear
	estimates clear
	
	// Newborn Health, part 2

	foreach y in w_food_3mo total_vacc vita_6wk vita_6mo { 
		eststo est`y': areg E`y' `y' `covars' `controls', absorb(stratum) cluster(villageid)		
		sum E`y' if control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`y'
		test whn=wemp
			estadd scalar pval1=r(p): est`y'
		test wemp=mhn
			estadd scalar pval2=r(p): est`y'
		test whn=mhn
			estadd scalar pval3=r(p): est`y'	
	}		

	// PANEL B, part 2: Maternal health (only for mothers who are currently pregnant or have been pregnant in the past 2 years before EL)	
		
	foreach y in w_latestpreg_ac2 w_latestpreg_foods2 iron { 
		eststo est`y': areg E`y' `y' `covars' `controls', absorb(stratum) cluster(villageid)		
		sum E`y' if control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`y'
		test whn=wemp
			estadd scalar pval1=r(p): est`y'
		test wemp=mhn
			estadd scalar pval2=r(p): est`y'
		test whn=mhn
			estadd scalar pval3=r(p): est`y'	
	}	
	#delimit ;
	esttab using "$tables/table_A7.tex", 
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets append gaps label booktabs  
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none) order(wemp whn mhn) 
		prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
		\begin{tabular}{@{\extracolsep{-6pt}}l*{7}{>{\centering\arraybackslash}m{2.0cm}}}
		\toprule
		&\multicolumn{4}{c}{\textbf{Newborn health}} &\multicolumn{3}{c}{\textbf{Maternal health}} \\
		\cmidrule(lr){2-5} \cmidrule(lr){6-8}
		& No solid foods in first 3 months & Number of vaccinations & Vitamin A in first 6 weeks & Vitamin A in last 6 months & Received antenatal care & Ate more of some foods during this pregnancy & Received iron during last pregnancy or in 2 months after \\")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean of outcome"  " "  "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f  %20s  %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr	
	
	// PANEL C: Household sanitary practices
	
	eststo clear
	estimates clear

	foreach y in m_soap_toilet_bi m_soap_meal_bi w_soap_toilet_bi w_soap_meal_bi w_treat_water w_toilet_sweep_bi {
		eststo est`y': areg E`y' `y' `covars' `controls', absorb(stratum) cluster(villageid)		
		sum E`y' if control==1 
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": est`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": est`y'
		test whn=wemp
			estadd scalar pval1=r(p): est`y'
		test wemp=mhn
			estadd scalar pval2=r(p): est`y'
		test whn=mhn
			estadd scalar pval3=r(p): est`y'	
	}		
	eststo est0: areg Ew_toilet_improv `covars' `controls', absorb(stratum) cluster(villageid)		
	sum Ew_toilet_improv if control==1 
	local num: display %4.3f `r(mean)'
		estadd local mean "`num'": est0
	local num: display %4.3f `r(sd)'
		estadd local sd "(`num')": est0
	test whn=wemp
		estadd scalar pval1=r(p): est0
	test wemp=mhn
		estadd scalar pval2=r(p): est0
	test whn=mhn
		estadd scalar pval3=r(p): est0		

	#delimit ;
	esttab using "$tables/table_A7.tex", 
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets append gaps label booktabs  
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none) order(wemp whn mhn) 
		prehead("{\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
		\begin{tabular}{@{\extracolsep{-6pt}}l*{7}{>{\centering\arraybackslash}m{2.0cm}}}
		\toprule
		&\multicolumn{7}{c}{\textbf{Household sanitary practices}} \\
		\cmidrule(lr){2-8}
		& Wash hands after toilet (Man) & Wash hands before a meal (Man) & Wash hands after toilet (Woman) & Wash hands before a meal (Man) & Treat drinking water & Sweep latrine at least twice a week & Made improvements to latrine \\
		\midrule") 
		postfoot("\bottomrule \bottomrule \end{tabular} }") posthead(" ")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean of outcome" " "  "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f  %20s  %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr	
		
		
	}	
	
	
	
*===============================================================================*			
* Table A.8: Program impacts on additional anthropometric outcomes and birth weight by measurement type.
*===============================================================================*		

	if `table_a8' == 1 {	
		
	use "$analysis/child_level_mcm.dta", clear		
		
	tab districtid, gen(district)
	drop district4	

	estimates clear
	eststo clear
	
	** clean up age variables
	
	cap drop birthyear birthmonth
	gen birthyear=year(birthdate)
	gen birthmonth=month(birthdate)
	
	* recode missing values in endline age based on birth month and year: 	
	gen flag_Eage=1 if inlist(Eage,999,.)
	replace Eage = Eanthro_date - birthdate if flag_Eage==1
	replace Eage = Eage*(12/365) if flag_Eage==1 
	drop flag_Eage
	replace Eage=. if Eage-age>30 & age!=. 
	replace Eage=round(Eage)
	
	* generate variable = child's age at the start of the intervention (February 2013)
	cap drop month day year february2013 age_start_t
	
	gen month=2
	gen day=1
	gen year=2013
	gen february2013 = mdy(month, day, year)
	format february2013 %td
	lab var february2013 "Start of intervention: February 2013"
	drop month day year
	
	gen age_start_t = february2013 - birthdate
	gen age_start_t_days = age_start_t
	lab var age_start_t_days "Age of child (in days) at the start of the intervention"	
	replace age_start_t = age_start_t*(12/365) 
	replace age_start_t = round(age_start_t) 
	lab var age_start_t "Age of child (in months) at the start of the intervention"	
	
	local controls 	district?
	local covars wemp whn mhn
	lab var wemp "WCommHN"

	** MUAC-for-age and Hb level
	
	foreach y in mfa c_hblevel  {
		eststo estimation`y': reghdfe E`y' `covars' `controls' female if age_start_t<=23, absorb(stratum Eage age_start_t) cluster(villageid)	
		sum E`y' if e(sample)==1 & control==1 & age_start_t<=23
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimation`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimation`y'
		test whn=wemp
			estadd scalar pval1 = r(p): estimation`y'
		test wemp=mhn
			estadd scalar pval2 = r(p): estimation`y'
		test whn=mhn
			estadd scalar pval3 = r(p): estimation`y'				
	}
	
	** Birth weight, by type of measurement: 
	
	gen Ebweight_kg = Ebirth_weight
	*replace Ebweight_kg = Ebirth_weight*1000 if Ebweight_units==1 // grams to kilograms: grams must be enumerator mistake, since value is 4.5
	replace Ebweight_kg = . if Ebweight_kg>5 // trimming top 5% of values
	
	foreach y in bweight_kg {
		eststo estimation`y'1: reghdfe E`y' `covars' `controls' female if Eweight_immcard==1 & age_start_t_days<=-28 & onlyin==2, absorb(stratum age_start_t) cluster(villageid)	
		sum E`y' if e(sample)==1 & control==1 & Eweight_immcard==1 & age_start_t_days<=-28 & onlyin==2
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimation`y'1
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimation`y'1
		test whn=wemp
			estadd scalar pval1 = r(p): estimation`y'1
		test wemp=mhn
			estadd scalar pval2 = r(p): estimation`y'1
		test whn=mhn
			estadd scalar pval3 = r(p): estimation`y'1	
	}
	
	foreach y in bweight_kg {
		eststo estimation`y'2: reghdfe E`y' `covars' `controls' female if Eweight_immcard==0 & age_start_t_days<=-28 & onlyin==2, absorb(stratum age_start_t) cluster(villageid)	
		sum E`y' if e(sample)==1 & control==1 & Eweight_immcard==0 & age_start_t_days<=-28 & onlyin==2
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimation`y'2
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimation`y'2
		test whn=wemp
			estadd scalar pval1 = r(p): estimation`y'2
		test wemp=mhn
			estadd scalar pval2 = r(p): estimation`y'2
		test whn=mhn
			estadd scalar pval3 = r(p): estimation`y'2		
	}
	
	foreach y in weight_immcard {
		eststo estimation`y': reghdfe E`y' `covars' `controls' if age_start_t_days<=-28 & Ebweight_kg!=. & onlyin==2, absorb(stratum age_start_t) cluster(villageid)	
		sum E`y' if e(sample)==1 & control==1 & age_start_t_days<=-28 & Ebweight_kg!=.
		local num: display %4.3f `r(mean)'
			estadd local mean "`num'": estimation`y'
		local num: display %4.3f `r(sd)'
			estadd local sd "(`num')": estimation`y'
		test whn=wemp
			estadd scalar pval1 = r(p): estimation`y'
		test wemp=mhn
			estadd scalar pval2 = r(p): estimation`y'
		test whn=mhn
			estadd scalar pval3 = r(p): estimation`y'		
	}
	
	** Output results to TABLE A8
	#delimit ;
	esttab using "$tables/table_A8.tex", 
		b(3) se(3) star(* .1 ** .05 *** .01) nonotes nonumber brackets replace gaps label booktabs style(tex) 
		keep(wemp whn mhn) collabels(,none) mlabels(,none) eqlabel(,none)
		order(wemp whn mhn) prehead(" { \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi} 
		\begin{tabular}{l*{5}{c}} \toprule \toprule 
		&\multicolumn{1}{c}{(1)} &\multicolumn{1}{c}{(2)} &\multicolumn{1}{c}{(3)} &\multicolumn{1}{c}{(4)} &\multicolumn{1}{c}{(5)}  \\ 
		\midrule
		& MUAC-for-age & Hb level & Birth weight,   & Birth weight,    & Weight was  \\
		& Z-score 	   & (g/dl)   & new babies      & new babies       & read off  \\
		&  	           &          & (KG) 			& (KG)             & birth card \\
		& 		       &          & (birth card)    & (self-reported)  & (yes/no) \\
		\midrule")
		posthead(" ")
		postfoot("\bottomrule\bottomrule \end{tabular} }")
		stats(mean sd pval1 pval2 pval3 N, 
		labels("Control mean of outcome" " " "p-value: WCommHN=WHN" "p-value: WCommHN=MHN" "p-value: WHN=MHN" "Observations") 
		fmt(%4.3f %20s %4.3f %4.3f %4.3f %9.0fc));
	#delimit cr	
}

	
*===============================================================================*			
* Figure 1: Program impacts on children's intake of animal-sourced foods.
*===============================================================================*		
	
	if `figure_a1' == 1{
			use "$analysis/child_level_mcm.dta", clear
		
		tab districtid, gen(district)
		drop district4	
		
		collapse (mean) organ meat egg fish Eorgan Emeat Eegg Efish, by(id control wemp whn mhn) 	

		egen ASF=rowmax(Eorgan Emeat Eegg Efish)
		
		gen treatment_status=0 if control==1
		replace treatment_status=1 if wemp==1
		replace treatment_status=2 if whn==1
		replace treatment_status=3 if mhn==1
		lab define TSTATUS 0 "Control" 1 "WCommHN" 2 "WHN" 3 "MHN", modify
		lab values treatment_status TSTATUS
			
		#delimit ;
		cibar ASF, over(treatment_status) graphopts(legend(pos(6) row(1)) ylabel(0(0.04)0.24) ytitle("share of children aged 6-84 months who ate animal-sourced foods", size(small)) scheme(plotplainblind) 
			title("Children's intake of animal-sourced foods at endline")) ciopts(lwidth(medthin)) barlabel(on) blgap(0.002) blposition(nw) blcolor(black*0.6)
		;
		#delimit cr	
		graph export "$figures\figure_A1.pdf", as(pdf) replace	
	}
	
	
	
	
	